<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>Models &#8212; pgmpy 0.1.2 documentation</title>
    
    <link rel="stylesheet" href="_static/sphinxdoc.css" type="text/css" />
    <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    './',
        VERSION:     '0.1.2',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true,
        SOURCELINK_SUFFIX: '.txt'
      };
    </script>
    <script type="text/javascript" src="_static/jquery.js"></script>
    <script type="text/javascript" src="_static/underscore.js"></script>
    <script type="text/javascript" src="_static/doctools.js"></script>
    <link rel="index" title="Index" href="genindex.html" />
    <link rel="search" title="Search" href="search.html" />
    <link rel="next" title="Factor" href="factors.html" />
    <link rel="prev" title="Welcome to pgmpy’s documentation!" href="index.html" /> 
  </head>
  <body role="document">
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="factors.html" title="Factor"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="index.html" title="Welcome to pgmpy’s documentation!"
             accesskey="P">previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="index.html">pgmpy 0.1.2 documentation</a> &#187;</li> 
      </ul>
    </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
            <p class="logo"><a href="index.html">
              <img class="logo" src="_static/logo.png" alt="Logo"/>
            </a></p>
  <h3><a href="index.html">Table Of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">Models</a><ul>
<li><a class="reference internal" href="#module-pgmpy.models.BayesianModel">Bayesian Model</a></li>
<li><a class="reference internal" href="#module-pgmpy.models.MarkovModel">Markov Model</a></li>
<li><a class="reference internal" href="#module-pgmpy.models.FactorGraph">Factor Graph</a></li>
<li><a class="reference internal" href="#module-pgmpy.models.ClusterGraph">Cluster Graph</a></li>
<li><a class="reference internal" href="#module-pgmpy.models.JunctionTree">Junction Tree</a></li>
<li><a class="reference internal" href="#module-pgmpy.models.MarkovChain">Markov Chain</a></li>
<li><a class="reference internal" href="#module-pgmpy.models.NoisyOrModel">NoisyOr Model</a></li>
<li><a class="reference internal" href="#module-pgmpy.models.NaiveBayes">Naive Bayes</a></li>
<li><a class="reference internal" href="#module-pgmpy.models.DynamicBayesianNetwork">DynamicBayesianNetwork</a></li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="index.html"
                        title="previous chapter">Welcome to pgmpy&#8217;s documentation!</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="factors.html"
                        title="next chapter">Factor</a></p>
  <div role="note" aria-label="source link">
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="_sources/models.rst.txt"
            rel="nofollow">Show Source</a></li>
    </ul>
   </div>
<div id="searchbox" style="display: none" role="search">
  <h3>Quick search</h3>
    <form class="search" action="search.html" method="get">
      <div><input type="text" name="q" /></div>
      <div><input type="submit" value="Go" /></div>
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <div class="section" id="models">
<h1>Models<a class="headerlink" href="#models" title="Permalink to this headline">¶</a></h1>
<div class="section" id="module-pgmpy.models.BayesianModel">
<span id="bayesian-model"></span><h2>Bayesian Model<a class="headerlink" href="#module-pgmpy.models.BayesianModel" title="Permalink to this headline">¶</a></h2>
<dl class="class">
<dt id="pgmpy.models.BayesianModel.BayesianModel">
<em class="property">class </em><code class="descclassname">pgmpy.models.BayesianModel.</code><code class="descname">BayesianModel</code><span class="sig-paren">(</span><em>ebunch=None</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/BayesianModel.html#BayesianModel"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.BayesianModel.BayesianModel" title="Permalink to this definition">¶</a></dt>
<dd><p>Base class for bayesian model.</p>
<p>A models stores nodes and edges with conditional probability
distribution (cpd) and other attributes.</p>
<p>models hold directed edges.  Self loops are not allowed neither
multiple (parallel) edges.</p>
<p>Nodes can be any hashable python object.</p>
<p>Edges are represented as links between nodes.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>data</strong> : input graph</p>
<blockquote class="last">
<div><p>Data to initialize graph.  If data=None (default) an empty
graph is created.  The data can be an edge list, or any
NetworkX graph object.</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<p>Create an empty bayesian model with no nodes and no edges.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">BayesianModel</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span> <span class="o">=</span> <span class="n">BayesianModel</span><span class="p">()</span>
</pre></div>
</div>
<p>G can be grown in several ways.</p>
<p><strong>Nodes:</strong></p>
<p>Add one node at a time:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_node</span><span class="p">(</span><span class="s1">&#39;a&#39;</span><span class="p">)</span>
</pre></div>
</div>
<p>Add the nodes from any container (a list, set or tuple or the nodes
from another graph).</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_nodes_from</span><span class="p">([</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">])</span>
</pre></div>
</div>
<p><strong>Edges:</strong></p>
<p>G can also be grown by adding edges.</p>
<p>Add one edge,</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_edge</span><span class="p">(</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">)</span>
</pre></div>
</div>
<p>a list of edges,</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_edges_from</span><span class="p">([(</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="s1">&#39;c&#39;</span><span class="p">)])</span>
</pre></div>
</div>
<p>If some edges connect nodes not yet in the model, the nodes
are added automatically.  There are no errors when adding
nodes or edges that already exist.</p>
<p><strong>Shortcuts:</strong></p>
<p>Many common graph features allow python syntax for speed reporting.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="s1">&#39;a&#39;</span> <span class="ow">in</span> <span class="n">G</span>     <span class="c1"># check if node in graph</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">len</span><span class="p">(</span><span class="n">G</span><span class="p">)</span>  <span class="c1"># number of nodes in graph</span>
<span class="go">3</span>
</pre></div>
</div>
<dl class="method">
<dt id="pgmpy.models.BayesianModel.BayesianModel.active_trail_nodes">
<code class="descname">active_trail_nodes</code><span class="sig-paren">(</span><em>variables</em>, <em>observed=None</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/BayesianModel.html#BayesianModel.active_trail_nodes"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.BayesianModel.BayesianModel.active_trail_nodes" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns a dictionary with the given variables as keys and all the nodes reachable
from that respective variable as values.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>variables: str or array like</strong></p>
<blockquote>
<div><p>variables whose active trails are to be found.</p>
</div></blockquote>
<p><strong>observed</strong> : List of nodes (optional)</p>
<blockquote class="last">
<div><p>If given the active trails would be computed assuming these nodes to be observed.</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<p class="rubric">References</p>
<p>Details of the algorithm can be found in &#8216;Probabilistic Graphical Model
Principles and Techniques&#8217; - Koller and Friedman
Page 75 Algorithm 3.1</p>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">BayesianModel</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">student</span> <span class="o">=</span> <span class="n">BayesianModel</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">student</span><span class="o">.</span><span class="n">add_nodes_from</span><span class="p">([</span><span class="s1">&#39;diff&#39;</span><span class="p">,</span> <span class="s1">&#39;intel&#39;</span><span class="p">,</span> <span class="s1">&#39;grades&#39;</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">student</span><span class="o">.</span><span class="n">add_edges_from</span><span class="p">([(</span><span class="s1">&#39;diff&#39;</span><span class="p">,</span> <span class="s1">&#39;grades&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;intel&#39;</span><span class="p">,</span> <span class="s1">&#39;grades&#39;</span><span class="p">)])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">student</span><span class="o">.</span><span class="n">active_trail_nodes</span><span class="p">(</span><span class="s1">&#39;diff&#39;</span><span class="p">)</span>
<span class="go">{&#39;diff&#39;: {&#39;diff&#39;, &#39;grades&#39;}}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">student</span><span class="o">.</span><span class="n">active_trail_nodes</span><span class="p">([</span><span class="s1">&#39;diff&#39;</span><span class="p">,</span> <span class="s1">&#39;intel&#39;</span><span class="p">],</span> <span class="n">observed</span><span class="o">=</span><span class="s1">&#39;grades&#39;</span><span class="p">)</span>
<span class="go">{&#39;diff&#39;: {&#39;diff&#39;, &#39;intel&#39;}, &#39;intel&#39;: {&#39;diff&#39;, &#39;intel&#39;}}</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.BayesianModel.BayesianModel.add_cpds">
<code class="descname">add_cpds</code><span class="sig-paren">(</span><em>*cpds</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/BayesianModel.html#BayesianModel.add_cpds"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.BayesianModel.BayesianModel.add_cpds" title="Permalink to this definition">¶</a></dt>
<dd><p>Add CPD (Conditional Probability Distribution) to the Bayesian Model.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>cpds</strong> :  list, set, tuple (array-like)</p>
<blockquote class="last">
<div><p>List of CPDs which will be associated with the model</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.BayesianModel.BayesianModel.add_edge">
<code class="descname">add_edge</code><span class="sig-paren">(</span><em>u</em>, <em>v</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/BayesianModel.html#BayesianModel.add_edge"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.BayesianModel.BayesianModel.add_edge" title="Permalink to this definition">¶</a></dt>
<dd><p>Add an edge between u and v.</p>
<p>The nodes u and v will be automatically added if they are
not already in the graph</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>u,v</strong> : nodes</p>
<blockquote class="last">
<div><p>Nodes can be any hashable python object.</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">BayesianModel</span><span class="o">/</span><span class="n">home</span><span class="o">/</span><span class="n">abinash</span><span class="o">/</span><span class="n">software_packages</span><span class="o">/</span><span class="n">numpy</span><span class="o">-</span><span class="mf">1.7</span><span class="o">.</span><span class="mi">1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span> <span class="o">=</span> <span class="n">BayesianModel</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_nodes_from</span><span class="p">([</span><span class="s1">&#39;grade&#39;</span><span class="p">,</span> <span class="s1">&#39;intel&#39;</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_edge</span><span class="p">(</span><span class="s1">&#39;grade&#39;</span><span class="p">,</span> <span class="s1">&#39;intel&#39;</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.BayesianModel.BayesianModel.check_model">
<code class="descname">check_model</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/BayesianModel.html#BayesianModel.check_model"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.BayesianModel.BayesianModel.check_model" title="Permalink to this definition">¶</a></dt>
<dd><p>Check the model for various errors. This method checks for the following
errors.</p>
<ul class="simple">
<li>Checks if the sum of the probabilities for each state is equal to 1 (tol=0.01).</li>
<li>Checks if the CPDs associated with nodes are consistent with their parents.</li>
</ul>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">check: boolean</p>
<blockquote class="last">
<div><p>True if all the checks are passed</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.BayesianModel.BayesianModel.copy">
<code class="descname">copy</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/BayesianModel.html#BayesianModel.copy"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.BayesianModel.BayesianModel.copy" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns a copy of the model.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">BayesianModel: Copy of the model on which the method was called.</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">BayesianModel</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.factors.discrete</span> <span class="k">import</span> <span class="n">TabularCPD</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">model</span> <span class="o">=</span> <span class="n">BayesianModel</span><span class="p">([(</span><span class="s1">&#39;A&#39;</span><span class="p">,</span> <span class="s1">&#39;B&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;B&#39;</span><span class="p">,</span> <span class="s1">&#39;C&#39;</span><span class="p">)])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">cpd_a</span> <span class="o">=</span> <span class="n">TabularCPD</span><span class="p">(</span><span class="s1">&#39;A&#39;</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="p">[[</span><span class="mf">0.2</span><span class="p">],</span> <span class="p">[</span><span class="mf">0.8</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">cpd_b</span> <span class="o">=</span> <span class="n">TabularCPD</span><span class="p">(</span><span class="s1">&#39;B&#39;</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="p">[[</span><span class="mf">0.3</span><span class="p">,</span> <span class="mf">0.7</span><span class="p">],</span> <span class="p">[</span><span class="mf">0.7</span><span class="p">,</span> <span class="mf">0.3</span><span class="p">]],</span>
<span class="go">                       evidence=[&#39;A&#39;],</span>
<span class="go">                       evidence_card=[2])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">cpd_c</span> <span class="o">=</span> <span class="n">TabularCPD</span><span class="p">(</span><span class="s1">&#39;C&#39;</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="p">[[</span><span class="mf">0.1</span><span class="p">,</span> <span class="mf">0.9</span><span class="p">],</span> <span class="p">[</span><span class="mf">0.9</span><span class="p">,</span> <span class="mf">0.1</span><span class="p">]],</span>
<span class="go">                       evidence=[&#39;B&#39;],</span>
<span class="go">                       evidence_card=[2])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">model</span><span class="o">.</span><span class="n">add_cpds</span><span class="p">(</span><span class="n">cpd_a</span><span class="p">,</span> <span class="n">cpd_b</span><span class="p">,</span> <span class="n">cpd_c</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">copy_model</span> <span class="o">=</span> <span class="n">model</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">copy_model</span><span class="o">.</span><span class="n">nodes</span><span class="p">()</span>
<span class="go">[&#39;C&#39;, &#39;A&#39;, &#39;B&#39;]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">copy_model</span><span class="o">.</span><span class="n">edges</span><span class="p">()</span>
<span class="go">[(&#39;A&#39;, &#39;B&#39;), (&#39;B&#39;, &#39;C&#39;)]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">copy_model</span><span class="o">.</span><span class="n">get_cpds</span><span class="p">()</span>
<span class="go">[&lt;TabularCPD representing P(A:2) at 0x7f2824930a58&gt;,</span>
<span class="go"> &lt;TabularCPD representing P(B:2 | A:2) at 0x7f2824930a90&gt;,</span>
<span class="go"> &lt;TabularCPD representing P(C:2 | B:2) at 0x7f2824944240&gt;]</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.BayesianModel.BayesianModel.fit">
<code class="descname">fit</code><span class="sig-paren">(</span><em>data</em>, <em>estimator=None</em>, <em>state_names=[]</em>, <em>complete_samples_only=True</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/BayesianModel.html#BayesianModel.fit"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.BayesianModel.BayesianModel.fit" title="Permalink to this definition">¶</a></dt>
<dd><p>Estimates the CPD for each variable based on a given data set.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>data: pandas DataFrame object</strong></p>
<blockquote>
<div><p>DataFrame object with column names identical to the variable names of the network.
(If some values in the data are missing the data cells should be set to <cite>numpy.NaN</cite>.
Note that pandas converts each column containing <cite>numpy.NaN`s to dtype `float</cite>.)</p>
</div></blockquote>
<p><strong>estimator: Estimator class</strong></p>
<blockquote>
<div><p>One of:
- MaximumLikelihoodEstimator (default)
- BayesianEstimator: In this case, pass &#8216;prior_type&#8217; and either &#8216;pseudo_counts&#8217;</p>
<blockquote>
<div><p>or &#8216;equivalent_sample_size&#8217; as additional keyword arguments.
See <cite>BayesianEstimator.get_parameters()</cite> for usage.</p>
</div></blockquote>
</div></blockquote>
<p><strong>state_names: dict (optional)</strong></p>
<blockquote>
<div><p>A dict indicating, for each variable, the discrete set of states
that the variable can take. If unspecified, the observed values
in the data set are taken to be the only possible states.</p>
</div></blockquote>
<p><strong>complete_samples_only: bool (default `True`)</strong></p>
<blockquote class="last">
<div><p>Specifies how to deal with missing data, if present. If set to <cite>True</cite> all rows
that contain <cite>np.Nan</cite> somewhere are ignored. If <cite>False</cite> then, for each variable,
every row where neither the variable nor its parents are <cite>np.NaN</cite> is used.</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">pandas</span> <span class="k">as</span> <span class="nn">pd</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">BayesianModel</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.estimators</span> <span class="k">import</span> <span class="n">MaximumLikelihoodEstimator</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">data</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">(</span><span class="n">data</span><span class="o">=</span><span class="p">{</span><span class="s1">&#39;A&#39;</span><span class="p">:</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">],</span> <span class="s1">&#39;B&#39;</span><span class="p">:</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="s1">&#39;C&#39;</span><span class="p">:</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">]})</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">model</span> <span class="o">=</span> <span class="n">BayesianModel</span><span class="p">([(</span><span class="s1">&#39;A&#39;</span><span class="p">,</span> <span class="s1">&#39;C&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;B&#39;</span><span class="p">,</span> <span class="s1">&#39;C&#39;</span><span class="p">)])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">model</span><span class="o">.</span><span class="n">fit</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">model</span><span class="o">.</span><span class="n">get_cpds</span><span class="p">()</span>
<span class="go">[&lt;TabularCPD representing P(A:2) at 0x7fb98a7d50f0&gt;,</span>
<span class="go">&lt;TabularCPD representing P(B:2) at 0x7fb98a7d5588&gt;,</span>
<span class="go">&lt;TabularCPD representing P(C:2 | A:2, B:2) at 0x7fb98a7b1f98&gt;]</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.BayesianModel.BayesianModel.get_cardinality">
<code class="descname">get_cardinality</code><span class="sig-paren">(</span><em>node=None</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/BayesianModel.html#BayesianModel.get_cardinality"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.BayesianModel.BayesianModel.get_cardinality" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the cardinality of the node. Throws an error if the CPD for the
queried node hasn&#8217;t been added to the network.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>node: Any hashable python object(optional).</strong></p>
<blockquote>
<div><p>The node whose cardinality we want. If node is not specified returns a
dictionary with the given variable as keys and their respective cardinality
as values.</p>
</div></blockquote>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><strong>int or dict</strong> : If node is specified returns the cardinality of the node.</p>
<blockquote class="last">
<div><p>If node is not specified returns a dictionary with the given
variable as keys and their respective cardinality as values.</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">BayesianModel</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.factors.discrete</span> <span class="k">import</span> <span class="n">TabularCPD</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">student</span> <span class="o">=</span> <span class="n">BayesianModel</span><span class="p">([(</span><span class="s1">&#39;diff&#39;</span><span class="p">,</span> <span class="s1">&#39;grade&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;intel&#39;</span><span class="p">,</span> <span class="s1">&#39;grade&#39;</span><span class="p">)])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">cpd_diff</span> <span class="o">=</span> <span class="n">TabularCPD</span><span class="p">(</span><span class="s1">&#39;diff&#39;</span><span class="p">,</span><span class="mi">2</span><span class="p">,[[</span><span class="mf">0.6</span><span class="p">,</span><span class="mf">0.4</span><span class="p">]]);</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">cpd_intel</span> <span class="o">=</span> <span class="n">TabularCPD</span><span class="p">(</span><span class="s1">&#39;intel&#39;</span><span class="p">,</span><span class="mi">2</span><span class="p">,[[</span><span class="mf">0.7</span><span class="p">,</span><span class="mf">0.3</span><span class="p">]]);</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">cpd_grade</span> <span class="o">=</span> <span class="n">TabularCPD</span><span class="p">(</span><span class="s1">&#39;grade&#39;</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="p">[[</span><span class="mf">0.1</span><span class="p">,</span> <span class="mf">0.9</span><span class="p">,</span> <span class="mf">0.2</span><span class="p">,</span> <span class="mf">0.7</span><span class="p">],</span>
<span class="gp">... </span>                                    <span class="p">[</span><span class="mf">0.9</span><span class="p">,</span> <span class="mf">0.1</span><span class="p">,</span> <span class="mf">0.8</span><span class="p">,</span> <span class="mf">0.3</span><span class="p">]],</span>
<span class="gp">... </span>                                <span class="p">[</span><span class="s1">&#39;intel&#39;</span><span class="p">,</span> <span class="s1">&#39;diff&#39;</span><span class="p">],</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">student</span><span class="o">.</span><span class="n">add_cpds</span><span class="p">(</span><span class="n">cpd_diff</span><span class="p">,</span><span class="n">cpd_intel</span><span class="p">,</span><span class="n">cpd_grade</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">student</span><span class="o">.</span><span class="n">get_cardinality</span><span class="p">()</span>
<span class="go">defaultdict(int, {&#39;diff&#39;: 2, &#39;grade&#39;: 2, &#39;intel&#39;: 2})</span>
</pre></div>
</div>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">student</span><span class="o">.</span><span class="n">get_cardinality</span><span class="p">(</span><span class="s1">&#39;intel&#39;</span><span class="p">)</span>
<span class="go">2</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.BayesianModel.BayesianModel.get_cpds">
<code class="descname">get_cpds</code><span class="sig-paren">(</span><em>node=None</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/BayesianModel.html#BayesianModel.get_cpds"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.BayesianModel.BayesianModel.get_cpds" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the cpd of the node. If node is not specified returns all the CPDs
that have been added till now to the graph</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">A list of TabularCPDs.</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">BayesianModel</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.factors.discrete</span> <span class="k">import</span> <span class="n">TabularCPD</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">student</span> <span class="o">=</span> <span class="n">BayesianModel</span><span class="p">([(</span><span class="s1">&#39;diff&#39;</span><span class="p">,</span> <span class="s1">&#39;grade&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;intel&#39;</span><span class="p">,</span> <span class="s1">&#39;grade&#39;</span><span class="p">)])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">cpd</span> <span class="o">=</span> <span class="n">TabularCPD</span><span class="p">(</span><span class="s1">&#39;grade&#39;</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="p">[[</span><span class="mf">0.1</span><span class="p">,</span> <span class="mf">0.9</span><span class="p">,</span> <span class="mf">0.2</span><span class="p">,</span> <span class="mf">0.7</span><span class="p">],</span>
<span class="gp">... </span>                              <span class="p">[</span><span class="mf">0.9</span><span class="p">,</span> <span class="mf">0.1</span><span class="p">,</span> <span class="mf">0.8</span><span class="p">,</span> <span class="mf">0.3</span><span class="p">]],</span>
<span class="gp">... </span>                 <span class="p">[</span><span class="s1">&#39;intel&#39;</span><span class="p">,</span> <span class="s1">&#39;diff&#39;</span><span class="p">],</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">student</span><span class="o">.</span><span class="n">add_cpds</span><span class="p">(</span><span class="n">cpd</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">student</span><span class="o">.</span><span class="n">get_cpds</span><span class="p">()</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.BayesianModel.BayesianModel.get_factorized_product">
<code class="descname">get_factorized_product</code><span class="sig-paren">(</span><em>latex=False</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/BayesianModel.html#BayesianModel.get_factorized_product"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.BayesianModel.BayesianModel.get_factorized_product" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="method">
<dt id="pgmpy.models.BayesianModel.BayesianModel.get_immoralities">
<code class="descname">get_immoralities</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/BayesianModel.html#BayesianModel.get_immoralities"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.BayesianModel.BayesianModel.get_immoralities" title="Permalink to this definition">¶</a></dt>
<dd><p>Finds all the immoralities in the model
A v-structure X -&gt; Z &lt;- Y is an immorality if there is no direct edge between X and Y .</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">set: A set of all the immoralities in the model</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">BayesianModel</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">student</span> <span class="o">=</span> <span class="n">BayesianModel</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">student</span><span class="o">.</span><span class="n">add_edges_from</span><span class="p">([(</span><span class="s1">&#39;diff&#39;</span><span class="p">,</span> <span class="s1">&#39;grade&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;intel&#39;</span><span class="p">,</span> <span class="s1">&#39;grade&#39;</span><span class="p">),</span>
<span class="gp">... </span>                        <span class="p">(</span><span class="s1">&#39;intel&#39;</span><span class="p">,</span> <span class="s1">&#39;SAT&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;grade&#39;</span><span class="p">,</span> <span class="s1">&#39;letter&#39;</span><span class="p">)])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">student</span><span class="o">.</span><span class="n">get_immoralities</span><span class="p">()</span>
<span class="go">{(&#39;diff&#39;,&#39;intel&#39;)}</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.BayesianModel.BayesianModel.get_independencies">
<code class="descname">get_independencies</code><span class="sig-paren">(</span><em>latex=False</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/BayesianModel.html#BayesianModel.get_independencies"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.BayesianModel.BayesianModel.get_independencies" title="Permalink to this definition">¶</a></dt>
<dd><p>Computes independencies in the Bayesian Network, by checking d-seperation.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>latex: boolean</strong></p>
<blockquote class="last">
<div><p>If latex=True then latex string of the independence assertion
would be created.</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">BayesianModel</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">chain</span> <span class="o">=</span> <span class="n">BayesianModel</span><span class="p">([(</span><span class="s1">&#39;X&#39;</span><span class="p">,</span> <span class="s1">&#39;Y&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;Y&#39;</span><span class="p">,</span> <span class="s1">&#39;Z&#39;</span><span class="p">)])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">chain</span><span class="o">.</span><span class="n">get_independencies</span><span class="p">()</span>
<span class="go">(X _|_ Z | Y)</span>
<span class="go">(Z _|_ X | Y)</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.BayesianModel.BayesianModel.is_active_trail">
<code class="descname">is_active_trail</code><span class="sig-paren">(</span><em>start</em>, <em>end</em>, <em>observed=None</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/BayesianModel.html#BayesianModel.is_active_trail"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.BayesianModel.BayesianModel.is_active_trail" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns True if there is any active trail between start and end node</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>start</strong> : Graph Node</p>
<p><strong>end</strong> : Graph Node</p>
<p><strong>observed</strong> : List of nodes (optional)</p>
<blockquote>
<div><p>If given the active trail would be computed assuming these nodes to be observed.</p>
</div></blockquote>
<p><strong>additional_observed</strong> : List of nodes (optional)</p>
<blockquote class="last">
<div><p>If given the active trail would be computed assuming these nodes to be observed along with
the nodes marked as observed in the model.</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">BayesianModel</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">student</span> <span class="o">=</span> <span class="n">BayesianModel</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">student</span><span class="o">.</span><span class="n">add_nodes_from</span><span class="p">([</span><span class="s1">&#39;diff&#39;</span><span class="p">,</span> <span class="s1">&#39;intel&#39;</span><span class="p">,</span> <span class="s1">&#39;grades&#39;</span><span class="p">,</span> <span class="s1">&#39;letter&#39;</span><span class="p">,</span> <span class="s1">&#39;sat&#39;</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">student</span><span class="o">.</span><span class="n">add_edges_from</span><span class="p">([(</span><span class="s1">&#39;diff&#39;</span><span class="p">,</span> <span class="s1">&#39;grades&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;intel&#39;</span><span class="p">,</span> <span class="s1">&#39;grades&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;grades&#39;</span><span class="p">,</span> <span class="s1">&#39;letter&#39;</span><span class="p">),</span>
<span class="gp">... </span>                        <span class="p">(</span><span class="s1">&#39;intel&#39;</span><span class="p">,</span> <span class="s1">&#39;sat&#39;</span><span class="p">)])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">student</span><span class="o">.</span><span class="n">is_active_trail</span><span class="p">(</span><span class="s1">&#39;diff&#39;</span><span class="p">,</span> <span class="s1">&#39;intel&#39;</span><span class="p">)</span>
<span class="go">False</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">student</span><span class="o">.</span><span class="n">is_active_trail</span><span class="p">(</span><span class="s1">&#39;grades&#39;</span><span class="p">,</span> <span class="s1">&#39;sat&#39;</span><span class="p">)</span>
<span class="go">True</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.BayesianModel.BayesianModel.is_iequivalent">
<code class="descname">is_iequivalent</code><span class="sig-paren">(</span><em>model</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/BayesianModel.html#BayesianModel.is_iequivalent"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.BayesianModel.BayesianModel.is_iequivalent" title="Permalink to this definition">¶</a></dt>
<dd><p>Checks whether the given model is I-equivalent</p>
<p>Two graphs G1 and G2 are said to be I-equivalent if they have same skeleton
and have same set of immoralities.</p>
<p>Note: For same skeleton different names of nodes can work but for immoralities
names of nodes must be same</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>model</strong> : A Bayesian model object, for which you want to check I-equivalence</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><strong>boolean</strong> : True if both are I-equivalent, False otherwise</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">BayesianModel</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span> <span class="o">=</span> <span class="n">BayesianModel</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_edges_from</span><span class="p">([(</span><span class="s1">&#39;V&#39;</span><span class="p">,</span> <span class="s1">&#39;W&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;W&#39;</span><span class="p">,</span> <span class="s1">&#39;X&#39;</span><span class="p">),</span>
<span class="gp">... </span>                  <span class="p">(</span><span class="s1">&#39;X&#39;</span><span class="p">,</span> <span class="s1">&#39;Y&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;Z&#39;</span><span class="p">,</span> <span class="s1">&#39;Y&#39;</span><span class="p">)])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G1</span> <span class="o">=</span> <span class="n">BayesianModel</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G1</span><span class="o">.</span><span class="n">add_edges_from</span><span class="p">([(</span><span class="s1">&#39;W&#39;</span><span class="p">,</span> <span class="s1">&#39;V&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;X&#39;</span><span class="p">,</span> <span class="s1">&#39;W&#39;</span><span class="p">),</span>
<span class="gp">... </span>                   <span class="p">(</span><span class="s1">&#39;X&#39;</span><span class="p">,</span> <span class="s1">&#39;Y&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;Z&#39;</span><span class="p">,</span> <span class="s1">&#39;Y&#39;</span><span class="p">)])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">is_iequivalent</span><span class="p">(</span><span class="n">G1</span><span class="p">)</span>
<span class="go">True</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.BayesianModel.BayesianModel.is_imap">
<code class="descname">is_imap</code><span class="sig-paren">(</span><em>JPD</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/BayesianModel.html#BayesianModel.is_imap"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.BayesianModel.BayesianModel.is_imap" title="Permalink to this definition">¶</a></dt>
<dd><p>Checks whether the bayesian model is Imap of given JointProbabilityDistribution</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>JPD</strong> : An instance of JointProbabilityDistribution Class, for which you want to</p>
<blockquote>
<div><p>check the Imap</p>
</div></blockquote>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><strong>boolean</strong> : True if bayesian model is Imap for given Joint Probability Distribution</p>
<blockquote>
<div><p>False otherwise</p>
</div></blockquote>
<p>Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">BayesianModel</span>
</pre></div>
</div>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.factors.discrete</span> <span class="k">import</span> <span class="n">TabularCPD</span>
</pre></div>
</div>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.factors.discrete</span> <span class="k">import</span> <span class="n">JointProbabilityDistribution</span>
</pre></div>
</div>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">G</span> <span class="o">=</span> <span class="n">BayesianModel</span><span class="p">([(</span><span class="s1">&#39;diff&#39;</span><span class="p">,</span> <span class="s1">&#39;grade&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;intel&#39;</span><span class="p">,</span> <span class="s1">&#39;grade&#39;</span><span class="p">)])</span>
</pre></div>
</div>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">diff_cpd</span> <span class="o">=</span> <span class="n">TabularCPD</span><span class="p">(</span><span class="s1">&#39;diff&#39;</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="p">[[</span><span class="mf">0.2</span><span class="p">],</span> <span class="p">[</span><span class="mf">0.8</span><span class="p">]])</span>
</pre></div>
</div>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">intel_cpd</span> <span class="o">=</span> <span class="n">TabularCPD</span><span class="p">(</span><span class="s1">&#39;intel&#39;</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="p">[[</span><span class="mf">0.5</span><span class="p">],</span> <span class="p">[</span><span class="mf">0.3</span><span class="p">],</span> <span class="p">[</span><span class="mf">0.2</span><span class="p">]])</span>
</pre></div>
</div>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">grade_cpd</span> <span class="o">=</span> <span class="n">TabularCPD</span><span class="p">(</span><span class="s1">&#39;grade&#39;</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span>
</pre></div>
</div>
<p>...                        [[0.1,0.1,0.1,0.1,0.1,0.1],</p>
<p>...                         [0.1,0.1,0.1,0.1,0.1,0.1],</p>
<p>...                         [0.8,0.8,0.8,0.8,0.8,0.8]],</p>
<p>...                        evidence=[&#8216;diff&#8217;, &#8216;intel&#8217;],</p>
<p>...                        evidence_card=[2, 3])</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_cpds</span><span class="p">(</span><span class="n">diff_cpd</span><span class="p">,</span> <span class="n">intel_cpd</span><span class="p">,</span> <span class="n">grade_cpd</span><span class="p">)</span>
</pre></div>
</div>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">val</span> <span class="o">=</span> <span class="p">[</span><span class="mf">0.01</span><span class="p">,</span> <span class="mf">0.01</span><span class="p">,</span> <span class="mf">0.08</span><span class="p">,</span> <span class="mf">0.006</span><span class="p">,</span> <span class="mf">0.006</span><span class="p">,</span> <span class="mf">0.048</span><span class="p">,</span> <span class="mf">0.004</span><span class="p">,</span> <span class="mf">0.004</span><span class="p">,</span> <span class="mf">0.032</span><span class="p">,</span>
</pre></div>
</div>
<blockquote>
<div><p>0.04, 0.04, 0.32, 0.024, 0.024, 0.192, 0.016, 0.016, 0.128]</p>
</div></blockquote>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">JPD</span> <span class="o">=</span> <span class="n">JointProbabilityDistribution</span><span class="p">([</span><span class="s1">&#39;diff&#39;</span><span class="p">,</span> <span class="s1">&#39;intel&#39;</span><span class="p">,</span> <span class="s1">&#39;grade&#39;</span><span class="p">],</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">3</span><span class="p">],</span> <span class="n">val</span><span class="p">)</span>
</pre></div>
</div>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">is_imap</span><span class="p">(</span><span class="n">JPD</span><span class="p">)</span>
</pre></div>
</div>
<p class="last">True</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.BayesianModel.BayesianModel.local_independencies">
<code class="descname">local_independencies</code><span class="sig-paren">(</span><em>variables</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/BayesianModel.html#BayesianModel.local_independencies"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.BayesianModel.BayesianModel.local_independencies" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns an instance of Independencies containing the local independencies
of each of the variables.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>variables: str or array like</strong></p>
<blockquote class="last">
<div><p>variables whose local independencies are to be found.</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">BayesianModel</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">student</span> <span class="o">=</span> <span class="n">BayesianModel</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">student</span><span class="o">.</span><span class="n">add_edges_from</span><span class="p">([(</span><span class="s1">&#39;diff&#39;</span><span class="p">,</span> <span class="s1">&#39;grade&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;intel&#39;</span><span class="p">,</span> <span class="s1">&#39;grade&#39;</span><span class="p">),</span>
<span class="gp">&gt;&gt;&gt; </span>                        <span class="p">(</span><span class="s1">&#39;grade&#39;</span><span class="p">,</span> <span class="s1">&#39;letter&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;intel&#39;</span><span class="p">,</span> <span class="s1">&#39;SAT&#39;</span><span class="p">)])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ind</span> <span class="o">=</span> <span class="n">student</span><span class="o">.</span><span class="n">local_independencies</span><span class="p">(</span><span class="s1">&#39;grade&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ind</span>
<span class="go">(grade _|_ SAT | diff, intel)</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.BayesianModel.BayesianModel.predict">
<code class="descname">predict</code><span class="sig-paren">(</span><em>data</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/BayesianModel.html#BayesianModel.predict"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.BayesianModel.BayesianModel.predict" title="Permalink to this definition">¶</a></dt>
<dd><p>Predicts states of all the missing variables.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>data</strong> : pandas DataFrame object</p>
<blockquote class="last">
<div><p>A DataFrame object with column names same as the variables in the model.</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">pandas</span> <span class="k">as</span> <span class="nn">pd</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">BayesianModel</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">values</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">randint</span><span class="p">(</span><span class="n">low</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">high</span><span class="o">=</span><span class="mi">2</span><span class="p">,</span> <span class="n">size</span><span class="o">=</span><span class="p">(</span><span class="mi">1000</span><span class="p">,</span> <span class="mi">5</span><span class="p">)),</span>
<span class="gp">... </span>                      <span class="n">columns</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;A&#39;</span><span class="p">,</span> <span class="s1">&#39;B&#39;</span><span class="p">,</span> <span class="s1">&#39;C&#39;</span><span class="p">,</span> <span class="s1">&#39;D&#39;</span><span class="p">,</span> <span class="s1">&#39;E&#39;</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">train_data</span> <span class="o">=</span> <span class="n">values</span><span class="p">[:</span><span class="mi">800</span><span class="p">]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">predict_data</span> <span class="o">=</span> <span class="n">values</span><span class="p">[</span><span class="mi">800</span><span class="p">:]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">model</span> <span class="o">=</span> <span class="n">BayesianModel</span><span class="p">([(</span><span class="s1">&#39;A&#39;</span><span class="p">,</span> <span class="s1">&#39;B&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;C&#39;</span><span class="p">,</span> <span class="s1">&#39;B&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;C&#39;</span><span class="p">,</span> <span class="s1">&#39;D&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;B&#39;</span><span class="p">,</span> <span class="s1">&#39;E&#39;</span><span class="p">)])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">model</span><span class="o">.</span><span class="n">fit</span><span class="p">(</span><span class="n">values</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">predict_data</span> <span class="o">=</span> <span class="n">predict_data</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">predict_data</span><span class="o">.</span><span class="n">drop</span><span class="p">(</span><span class="s1">&#39;E&#39;</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">inplace</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">y_pred</span> <span class="o">=</span> <span class="n">model</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">predict_data</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">y_pred</span>
<span class="go">    E</span>
<span class="go">800 0</span>
<span class="go">801 1</span>
<span class="go">802 1</span>
<span class="go">803 1</span>
<span class="go">804 0</span>
<span class="gp">... </span><span class="o">...</span>
<span class="go">993 0</span>
<span class="go">994 0</span>
<span class="go">995 1</span>
<span class="go">996 1</span>
<span class="go">997 0</span>
<span class="go">998 0</span>
<span class="go">999 0</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.BayesianModel.BayesianModel.predict_probability">
<code class="descname">predict_probability</code><span class="sig-paren">(</span><em>data</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/BayesianModel.html#BayesianModel.predict_probability"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.BayesianModel.BayesianModel.predict_probability" title="Permalink to this definition">¶</a></dt>
<dd><p>Predicts probabilities of all states of the missing variables.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>data</strong> : pandas DataFrame object</p>
<blockquote class="last">
<div><p>A DataFrame object with column names same as the variables in the model.</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">pandas</span> <span class="k">as</span> <span class="nn">pd</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">BayesianModel</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">values</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">randint</span><span class="p">(</span><span class="n">low</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">high</span><span class="o">=</span><span class="mi">2</span><span class="p">,</span> <span class="n">size</span><span class="o">=</span><span class="p">(</span><span class="mi">100</span><span class="p">,</span> <span class="mi">5</span><span class="p">)),</span>
<span class="gp">... </span>                      <span class="n">columns</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;A&#39;</span><span class="p">,</span> <span class="s1">&#39;B&#39;</span><span class="p">,</span> <span class="s1">&#39;C&#39;</span><span class="p">,</span> <span class="s1">&#39;D&#39;</span><span class="p">,</span> <span class="s1">&#39;E&#39;</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">train_data</span> <span class="o">=</span> <span class="n">values</span><span class="p">[:</span><span class="mi">80</span><span class="p">]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">predict_data</span> <span class="o">=</span> <span class="n">values</span><span class="p">[</span><span class="mi">80</span><span class="p">:]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">model</span> <span class="o">=</span> <span class="n">BayesianModel</span><span class="p">([(</span><span class="s1">&#39;A&#39;</span><span class="p">,</span> <span class="s1">&#39;B&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;C&#39;</span><span class="p">,</span> <span class="s1">&#39;B&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;C&#39;</span><span class="p">,</span> <span class="s1">&#39;D&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;B&#39;</span><span class="p">,</span> <span class="s1">&#39;E&#39;</span><span class="p">)])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">model</span><span class="o">.</span><span class="n">fit</span><span class="p">(</span><span class="n">values</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">predict_data</span> <span class="o">=</span> <span class="n">predict_data</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">predict_data</span><span class="o">.</span><span class="n">drop</span><span class="p">(</span><span class="s1">&#39;B&#39;</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">inplace</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">y_prob</span> <span class="o">=</span> <span class="n">model</span><span class="o">.</span><span class="n">predict_probability</span><span class="p">(</span><span class="n">predict_data</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">y_prob</span>
<span class="go">    B_0         B_1</span>
<span class="go">80  0.439178    0.560822</span>
<span class="go">81  0.581970    0.418030</span>
<span class="go">82  0.488275    0.511725</span>
<span class="go">83  0.581970    0.418030</span>
<span class="go">84  0.510794    0.489206</span>
<span class="go">85  0.439178    0.560822</span>
<span class="go">86  0.439178    0.560822</span>
<span class="go">87  0.417124    0.582876</span>
<span class="go">88  0.407978    0.592022</span>
<span class="go">89  0.429905    0.570095</span>
<span class="go">90  0.581970    0.418030</span>
<span class="go">91  0.407978    0.592022</span>
<span class="go">92  0.429905    0.570095</span>
<span class="go">93  0.429905    0.570095</span>
<span class="go">94  0.439178    0.560822</span>
<span class="go">95  0.407978    0.592022</span>
<span class="go">96  0.559904    0.440096</span>
<span class="go">97  0.417124    0.582876</span>
<span class="go">98  0.488275    0.511725</span>
<span class="go">99  0.407978    0.592022</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.BayesianModel.BayesianModel.remove_cpds">
<code class="descname">remove_cpds</code><span class="sig-paren">(</span><em>*cpds</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/BayesianModel.html#BayesianModel.remove_cpds"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.BayesianModel.BayesianModel.remove_cpds" title="Permalink to this definition">¶</a></dt>
<dd><p>Removes the cpds that are provided in the argument.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>*cpds: TabularCPD object</strong></p>
<blockquote class="last">
<div><p>A CPD object on any subset of the variables of the model which
is to be associated with the model.</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">BayesianModel</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.factors.discrete</span> <span class="k">import</span> <span class="n">TabularCPD</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">student</span> <span class="o">=</span> <span class="n">BayesianModel</span><span class="p">([(</span><span class="s1">&#39;diff&#39;</span><span class="p">,</span> <span class="s1">&#39;grade&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;intel&#39;</span><span class="p">,</span> <span class="s1">&#39;grade&#39;</span><span class="p">)])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">cpd</span> <span class="o">=</span> <span class="n">TabularCPD</span><span class="p">(</span><span class="s1">&#39;grade&#39;</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="p">[[</span><span class="mf">0.1</span><span class="p">,</span> <span class="mf">0.9</span><span class="p">,</span> <span class="mf">0.2</span><span class="p">,</span> <span class="mf">0.7</span><span class="p">],</span>
<span class="gp">... </span>                              <span class="p">[</span><span class="mf">0.9</span><span class="p">,</span> <span class="mf">0.1</span><span class="p">,</span> <span class="mf">0.8</span><span class="p">,</span> <span class="mf">0.3</span><span class="p">]],</span>
<span class="gp">... </span>                 <span class="p">[</span><span class="s1">&#39;intel&#39;</span><span class="p">,</span> <span class="s1">&#39;diff&#39;</span><span class="p">],</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">student</span><span class="o">.</span><span class="n">add_cpds</span><span class="p">(</span><span class="n">cpd</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">student</span><span class="o">.</span><span class="n">remove_cpds</span><span class="p">(</span><span class="n">cpd</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.BayesianModel.BayesianModel.remove_node">
<code class="descname">remove_node</code><span class="sig-paren">(</span><em>node</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/BayesianModel.html#BayesianModel.remove_node"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.BayesianModel.BayesianModel.remove_node" title="Permalink to this definition">¶</a></dt>
<dd><p>Remove node from the model.</p>
<p>Removing a node also removes all the associated edges, removes the CPD
of the node and marginalizes the CPDs of it&#8217;s children.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>node</strong> : node</p>
<blockquote>
<div><p>Node which is to be removed from the model.</p>
</div></blockquote>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">None</p>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">pandas</span> <span class="k">as</span> <span class="nn">pd</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">BayesianModel</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">model</span> <span class="o">=</span> <span class="n">BayesianModel</span><span class="p">([(</span><span class="s1">&#39;A&#39;</span><span class="p">,</span> <span class="s1">&#39;B&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;B&#39;</span><span class="p">,</span> <span class="s1">&#39;C&#39;</span><span class="p">),</span>
<span class="gp">... </span>                       <span class="p">(</span><span class="s1">&#39;A&#39;</span><span class="p">,</span> <span class="s1">&#39;D&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;D&#39;</span><span class="p">,</span> <span class="s1">&#39;C&#39;</span><span class="p">)])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">values</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">randint</span><span class="p">(</span><span class="n">low</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">high</span><span class="o">=</span><span class="mi">2</span><span class="p">,</span> <span class="n">size</span><span class="o">=</span><span class="p">(</span><span class="mi">1000</span><span class="p">,</span> <span class="mi">4</span><span class="p">)),</span>
<span class="gp">... </span>                      <span class="n">columns</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;A&#39;</span><span class="p">,</span> <span class="s1">&#39;B&#39;</span><span class="p">,</span> <span class="s1">&#39;C&#39;</span><span class="p">,</span> <span class="s1">&#39;D&#39;</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">model</span><span class="o">.</span><span class="n">fit</span><span class="p">(</span><span class="n">values</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">model</span><span class="o">.</span><span class="n">get_cpds</span><span class="p">()</span>
<span class="go">[&lt;TabularCPD representing P(A:2) at 0x7f28248e2438&gt;,</span>
<span class="go"> &lt;TabularCPD representing P(B:2 | A:2) at 0x7f28248e23c8&gt;,</span>
<span class="go"> &lt;TabularCPD representing P(C:2 | B:2, D:2) at 0x7f28248e2748&gt;,</span>
<span class="go"> &lt;TabularCPD representing P(D:2 | A:2) at 0x7f28248e26a0&gt;]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">model</span><span class="o">.</span><span class="n">remove_node</span><span class="p">(</span><span class="s1">&#39;A&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">model</span><span class="o">.</span><span class="n">get_cpds</span><span class="p">()</span>
<span class="go">[&lt;TabularCPD representing P(B:2) at 0x7f28248e23c8&gt;,</span>
<span class="go"> &lt;TabularCPD representing P(C:2 | B:2, D:2) at 0x7f28248e2748&gt;,</span>
<span class="go"> &lt;TabularCPD representing P(D:2) at 0x7f28248e26a0&gt;]</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.BayesianModel.BayesianModel.remove_nodes_from">
<code class="descname">remove_nodes_from</code><span class="sig-paren">(</span><em>nodes</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/BayesianModel.html#BayesianModel.remove_nodes_from"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.BayesianModel.BayesianModel.remove_nodes_from" title="Permalink to this definition">¶</a></dt>
<dd><p>Remove multiple nodes from the model.</p>
<p>Removing a node also removes all the associated edges, removes the CPD
of the node and marginalizes the CPDs of it&#8217;s children.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>nodes</strong> : list, set (iterable)</p>
<blockquote>
<div><p>Nodes which are to be removed from the model.</p>
</div></blockquote>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">None</p>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">pandas</span> <span class="k">as</span> <span class="nn">pd</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">BayesianModel</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">model</span> <span class="o">=</span> <span class="n">BayesianModel</span><span class="p">([(</span><span class="s1">&#39;A&#39;</span><span class="p">,</span> <span class="s1">&#39;B&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;B&#39;</span><span class="p">,</span> <span class="s1">&#39;C&#39;</span><span class="p">),</span>
<span class="gp">... </span>                       <span class="p">(</span><span class="s1">&#39;A&#39;</span><span class="p">,</span> <span class="s1">&#39;D&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;D&#39;</span><span class="p">,</span> <span class="s1">&#39;C&#39;</span><span class="p">)])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">values</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">randint</span><span class="p">(</span><span class="n">low</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">high</span><span class="o">=</span><span class="mi">2</span><span class="p">,</span> <span class="n">size</span><span class="o">=</span><span class="p">(</span><span class="mi">1000</span><span class="p">,</span> <span class="mi">4</span><span class="p">)),</span>
<span class="gp">... </span>                      <span class="n">columns</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;A&#39;</span><span class="p">,</span> <span class="s1">&#39;B&#39;</span><span class="p">,</span> <span class="s1">&#39;C&#39;</span><span class="p">,</span> <span class="s1">&#39;D&#39;</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">model</span><span class="o">.</span><span class="n">fit</span><span class="p">(</span><span class="n">values</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">model</span><span class="o">.</span><span class="n">get_cpds</span><span class="p">()</span>
<span class="go">[&lt;TabularCPD representing P(A:2) at 0x7f28248e2438&gt;,</span>
<span class="go"> &lt;TabularCPD representing P(B:2 | A:2) at 0x7f28248e23c8&gt;,</span>
<span class="go"> &lt;TabularCPD representing P(C:2 | B:2, D:2) at 0x7f28248e2748&gt;,</span>
<span class="go"> &lt;TabularCPD representing P(D:2 | A:2) at 0x7f28248e26a0&gt;]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">model</span><span class="o">.</span><span class="n">remove_nodes_from</span><span class="p">([</span><span class="s1">&#39;A&#39;</span><span class="p">,</span> <span class="s1">&#39;B&#39;</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">model</span><span class="o">.</span><span class="n">get_cpds</span><span class="p">()</span>
<span class="go">[&lt;TabularCPD representing P(C:2 | D:2) at 0x7f28248e2a58&gt;,</span>
<span class="go"> &lt;TabularCPD representing P(D:2) at 0x7f28248e26d8&gt;]</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.BayesianModel.BayesianModel.to_junction_tree">
<code class="descname">to_junction_tree</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/BayesianModel.html#BayesianModel.to_junction_tree"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.BayesianModel.BayesianModel.to_junction_tree" title="Permalink to this definition">¶</a></dt>
<dd><p>Creates a junction tree (or clique tree) for a given bayesian model.</p>
<p>For converting a Bayesian Model into a Clique tree, first it is converted
into a Markov one.</p>
<p>For a given markov model (H) a junction tree (G) is a graph
1. where each node in G corresponds to a maximal clique in H
2. each sepset in G separates the variables strictly on one side of the
edge to other.</p>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">BayesianModel</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.factors.discrete</span> <span class="k">import</span> <span class="n">TabularCPD</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span> <span class="o">=</span> <span class="n">BayesianModel</span><span class="p">([(</span><span class="s1">&#39;diff&#39;</span><span class="p">,</span> <span class="s1">&#39;grade&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;intel&#39;</span><span class="p">,</span> <span class="s1">&#39;grade&#39;</span><span class="p">),</span>
<span class="gp">... </span>                   <span class="p">(</span><span class="s1">&#39;intel&#39;</span><span class="p">,</span> <span class="s1">&#39;SAT&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;grade&#39;</span><span class="p">,</span> <span class="s1">&#39;letter&#39;</span><span class="p">)])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">diff_cpd</span> <span class="o">=</span> <span class="n">TabularCPD</span><span class="p">(</span><span class="s1">&#39;diff&#39;</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="p">[[</span><span class="mf">0.2</span><span class="p">],</span> <span class="p">[</span><span class="mf">0.8</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">intel_cpd</span> <span class="o">=</span> <span class="n">TabularCPD</span><span class="p">(</span><span class="s1">&#39;intel&#39;</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="p">[[</span><span class="mf">0.5</span><span class="p">],</span> <span class="p">[</span><span class="mf">0.3</span><span class="p">],</span> <span class="p">[</span><span class="mf">0.2</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">grade_cpd</span> <span class="o">=</span> <span class="n">TabularCPD</span><span class="p">(</span><span class="s1">&#39;grade&#39;</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span>
<span class="gp">... </span>                       <span class="p">[[</span><span class="mf">0.1</span><span class="p">,</span><span class="mf">0.1</span><span class="p">,</span><span class="mf">0.1</span><span class="p">,</span><span class="mf">0.1</span><span class="p">,</span><span class="mf">0.1</span><span class="p">,</span><span class="mf">0.1</span><span class="p">],</span>
<span class="gp">... </span>                        <span class="p">[</span><span class="mf">0.1</span><span class="p">,</span><span class="mf">0.1</span><span class="p">,</span><span class="mf">0.1</span><span class="p">,</span><span class="mf">0.1</span><span class="p">,</span><span class="mf">0.1</span><span class="p">,</span><span class="mf">0.1</span><span class="p">],</span>
<span class="gp">... </span>                        <span class="p">[</span><span class="mf">0.8</span><span class="p">,</span><span class="mf">0.8</span><span class="p">,</span><span class="mf">0.8</span><span class="p">,</span><span class="mf">0.8</span><span class="p">,</span><span class="mf">0.8</span><span class="p">,</span><span class="mf">0.8</span><span class="p">]],</span>
<span class="gp">... </span>                       <span class="n">evidence</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;diff&#39;</span><span class="p">,</span> <span class="s1">&#39;intel&#39;</span><span class="p">],</span>
<span class="gp">... </span>                       <span class="n">evidence_card</span><span class="o">=</span><span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">sat_cpd</span> <span class="o">=</span> <span class="n">TabularCPD</span><span class="p">(</span><span class="s1">&#39;SAT&#39;</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span>
<span class="gp">... </span>                     <span class="p">[[</span><span class="mf">0.1</span><span class="p">,</span> <span class="mf">0.2</span><span class="p">,</span> <span class="mf">0.7</span><span class="p">],</span>
<span class="gp">... </span>                      <span class="p">[</span><span class="mf">0.9</span><span class="p">,</span> <span class="mf">0.8</span><span class="p">,</span> <span class="mf">0.3</span><span class="p">]],</span>
<span class="gp">... </span>                     <span class="n">evidence</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;intel&#39;</span><span class="p">],</span> <span class="n">evidence_card</span><span class="o">=</span><span class="p">[</span><span class="mi">3</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">letter_cpd</span> <span class="o">=</span> <span class="n">TabularCPD</span><span class="p">(</span><span class="s1">&#39;letter&#39;</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span>
<span class="gp">... </span>                        <span class="p">[[</span><span class="mf">0.1</span><span class="p">,</span> <span class="mf">0.4</span><span class="p">,</span> <span class="mf">0.8</span><span class="p">],</span>
<span class="gp">... </span>                         <span class="p">[</span><span class="mf">0.9</span><span class="p">,</span> <span class="mf">0.6</span><span class="p">,</span> <span class="mf">0.2</span><span class="p">]],</span>
<span class="gp">... </span>                        <span class="n">evidence</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;grade&#39;</span><span class="p">],</span> <span class="n">evidence_card</span><span class="o">=</span><span class="p">[</span><span class="mi">3</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_cpds</span><span class="p">(</span><span class="n">diff_cpd</span><span class="p">,</span> <span class="n">intel_cpd</span><span class="p">,</span> <span class="n">grade_cpd</span><span class="p">,</span> <span class="n">sat_cpd</span><span class="p">,</span> <span class="n">letter_cpd</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">jt</span> <span class="o">=</span> <span class="n">G</span><span class="o">.</span><span class="n">to_junction_tree</span><span class="p">()</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.BayesianModel.BayesianModel.to_markov_model">
<code class="descname">to_markov_model</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/BayesianModel.html#BayesianModel.to_markov_model"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.BayesianModel.BayesianModel.to_markov_model" title="Permalink to this definition">¶</a></dt>
<dd><p>Converts bayesian model to markov model. The markov model created would
be the moral graph of the bayesian model.</p>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">BayesianModel</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span> <span class="o">=</span> <span class="n">BayesianModel</span><span class="p">([(</span><span class="s1">&#39;diff&#39;</span><span class="p">,</span> <span class="s1">&#39;grade&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;intel&#39;</span><span class="p">,</span> <span class="s1">&#39;grade&#39;</span><span class="p">),</span>
<span class="gp">... </span>                   <span class="p">(</span><span class="s1">&#39;intel&#39;</span><span class="p">,</span> <span class="s1">&#39;SAT&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;grade&#39;</span><span class="p">,</span> <span class="s1">&#39;letter&#39;</span><span class="p">)])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">mm</span> <span class="o">=</span> <span class="n">G</span><span class="o">.</span><span class="n">to_markov_model</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">mm</span><span class="o">.</span><span class="n">nodes</span><span class="p">()</span>
<span class="go">[&#39;diff&#39;, &#39;grade&#39;, &#39;intel&#39;, &#39;SAT&#39;, &#39;letter&#39;]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">mm</span><span class="o">.</span><span class="n">edges</span><span class="p">()</span>
<span class="go">[(&#39;diff&#39;, &#39;intel&#39;), (&#39;diff&#39;, &#39;grade&#39;), (&#39;intel&#39;, &#39;grade&#39;),</span>
<span class="go">(&#39;intel&#39;, &#39;SAT&#39;), (&#39;grade&#39;, &#39;letter&#39;)]</span>
</pre></div>
</div>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="module-pgmpy.models.MarkovModel">
<span id="markov-model"></span><h2>Markov Model<a class="headerlink" href="#module-pgmpy.models.MarkovModel" title="Permalink to this headline">¶</a></h2>
<dl class="class">
<dt id="pgmpy.models.MarkovModel.MarkovModel">
<em class="property">class </em><code class="descclassname">pgmpy.models.MarkovModel.</code><code class="descname">MarkovModel</code><span class="sig-paren">(</span><em>ebunch=None</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/MarkovModel.html#MarkovModel"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.MarkovModel.MarkovModel" title="Permalink to this definition">¶</a></dt>
<dd><p>Base class for markov model.</p>
<p>A MarkovModel stores nodes and edges with potentials</p>
<p>MarkovModel holds undirected edges.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>data</strong> : input graph</p>
<blockquote class="last">
<div><p>Data to initialize graph.  If data=None (default) an empty
graph is created.  The data can be an edge list, or any
NetworkX graph object.</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<p>Create an empty Markov Model with no nodes and no edges.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">MarkovModel</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span> <span class="o">=</span> <span class="n">MarkovModel</span><span class="p">()</span>
</pre></div>
</div>
<p>G can be grown in several ways.</p>
<p><strong>Nodes:</strong></p>
<p>Add one node at a time:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_node</span><span class="p">(</span><span class="s1">&#39;a&#39;</span><span class="p">)</span>
</pre></div>
</div>
<p>Add the nodes from any container (a list, set or tuple or the nodes
from another graph).</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_nodes_from</span><span class="p">([</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">])</span>
</pre></div>
</div>
<p><strong>Edges:</strong></p>
<p>G can also be grown by adding edges.</p>
<p>Add one edge,</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_edge</span><span class="p">(</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">)</span>
</pre></div>
</div>
<p>a list of edges,</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_edges_from</span><span class="p">([(</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="s1">&#39;c&#39;</span><span class="p">)])</span>
</pre></div>
</div>
<p>If some edges connect nodes not yet in the model, the nodes
are added automatically.  There are no errors when adding
nodes or edges that already exist.</p>
<p><strong>Shortcuts:</strong></p>
<p>Many common graph features allow python syntax for speed reporting.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="s1">&#39;a&#39;</span> <span class="ow">in</span> <span class="n">G</span>     <span class="c1"># check if node in graph</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">len</span><span class="p">(</span><span class="n">G</span><span class="p">)</span>  <span class="c1"># number of nodes in graph</span>
<span class="go">3</span>
</pre></div>
</div>
<dl class="method">
<dt id="pgmpy.models.MarkovModel.MarkovModel.add_edge">
<code class="descname">add_edge</code><span class="sig-paren">(</span><em>u</em>, <em>v</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/MarkovModel.html#MarkovModel.add_edge"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.MarkovModel.MarkovModel.add_edge" title="Permalink to this definition">¶</a></dt>
<dd><p>Add an edge between u and v.</p>
<p>The nodes u and v will be automatically added if they are
not already in the graph</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>u,v</strong> : nodes</p>
<blockquote class="last">
<div><p>Nodes can be any hashable Python object.</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">MarkovModel</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span> <span class="o">=</span> <span class="n">MarkovModel</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_nodes_from</span><span class="p">([</span><span class="s1">&#39;Alice&#39;</span><span class="p">,</span> <span class="s1">&#39;Bob&#39;</span><span class="p">,</span> <span class="s1">&#39;Charles&#39;</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_edge</span><span class="p">(</span><span class="s1">&#39;Alice&#39;</span><span class="p">,</span> <span class="s1">&#39;Bob&#39;</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.MarkovModel.MarkovModel.add_factors">
<code class="descname">add_factors</code><span class="sig-paren">(</span><em>*factors</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/MarkovModel.html#MarkovModel.add_factors"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.MarkovModel.MarkovModel.add_factors" title="Permalink to this definition">¶</a></dt>
<dd><p>Associate a factor to the graph.
See factors class for the order of potential values</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>*factor: pgmpy.factors.factors object</strong></p>
<blockquote>
<div><p>A factor object on any subset of the variables of the model which
is to be associated with the model.</p>
</div></blockquote>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">None</p>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">MarkovModel</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.factors.discrete</span> <span class="k">import</span> <span class="n">DiscreteFactor</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">student</span> <span class="o">=</span> <span class="n">MarkovModel</span><span class="p">([(</span><span class="s1">&#39;Alice&#39;</span><span class="p">,</span> <span class="s1">&#39;Bob&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;Bob&#39;</span><span class="p">,</span> <span class="s1">&#39;Charles&#39;</span><span class="p">),</span>
<span class="gp">... </span>                       <span class="p">(</span><span class="s1">&#39;Charles&#39;</span><span class="p">,</span> <span class="s1">&#39;Debbie&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;Debbie&#39;</span><span class="p">,</span> <span class="s1">&#39;Alice&#39;</span><span class="p">)])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">factor</span> <span class="o">=</span> <span class="n">DiscreteFactor</span><span class="p">([</span><span class="s1">&#39;Alice&#39;</span><span class="p">,</span> <span class="s1">&#39;Bob&#39;</span><span class="p">],</span> <span class="n">cardinality</span><span class="o">=</span><span class="p">[</span><span class="mi">3</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span>
<span class="gp">... </span>                <span class="n">values</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">rand</span><span class="p">(</span><span class="mi">6</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">student</span><span class="o">.</span><span class="n">add_factors</span><span class="p">(</span><span class="n">factor</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.MarkovModel.MarkovModel.check_model">
<code class="descname">check_model</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/MarkovModel.html#MarkovModel.check_model"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.MarkovModel.MarkovModel.check_model" title="Permalink to this definition">¶</a></dt>
<dd><p>Check the model for various errors. This method checks for the following
errors -</p>
<ul class="simple">
<li>Checks if the cardinalities of all the variables are consistent across all the factors.</li>
<li>Factors are defined for all the random variables.</li>
</ul>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">check: boolean</p>
<blockquote class="last">
<div><p>True if all the checks are passed</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.MarkovModel.MarkovModel.copy">
<code class="descname">copy</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/MarkovModel.html#MarkovModel.copy"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.MarkovModel.MarkovModel.copy" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns a copy of this Markov Model.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">MarkovModel: Copy of this Markov model.</p>
<p>Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.factors.discrete</span> <span class="k">import</span> <span class="n">DiscreteFactor</span>
</pre></div>
</div>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">MarkovModel</span>
</pre></div>
</div>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">G</span> <span class="o">=</span> <span class="n">MarkovModel</span><span class="p">()</span>
</pre></div>
</div>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_nodes_from</span><span class="p">([(</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="s1">&#39;c&#39;</span><span class="p">)])</span>
</pre></div>
</div>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_edge</span><span class="p">((</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="s1">&#39;c&#39;</span><span class="p">))</span>
</pre></div>
</div>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">G_copy</span> <span class="o">=</span> <span class="n">G</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
</pre></div>
</div>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">G_copy</span><span class="o">.</span><span class="n">edges</span><span class="p">()</span>
</pre></div>
</div>
<p>[((&#8216;a&#8217;, &#8216;b&#8217;), (&#8216;b&#8217;, &#8216;c&#8217;))]</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">G_copy</span><span class="o">.</span><span class="n">nodes</span><span class="p">()</span>
</pre></div>
</div>
<p>[(&#8216;a&#8217;, &#8216;b&#8217;), (&#8216;b&#8217;, &#8216;c&#8217;)]</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">factor</span> <span class="o">=</span> <span class="n">DiscreteFactor</span><span class="p">([(</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">)],</span> <span class="n">cardinality</span><span class="o">=</span><span class="p">[</span><span class="mi">3</span><span class="p">],</span>
</pre></div>
</div>
<p>...                 values=np.random.rand(3))</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_factors</span><span class="p">(</span><span class="n">factor</span><span class="p">)</span>
</pre></div>
</div>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">get_factors</span><span class="p">()</span>
</pre></div>
</div>
<p>[&lt;DiscreteFactor representing phi((&#8216;a&#8217;, &#8216;b&#8217;):3) at 0x...&gt;]</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">G_copy</span><span class="o">.</span><span class="n">get_factors</span><span class="p">()</span>
</pre></div>
</div>
<p class="last">[]</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.MarkovModel.MarkovModel.get_cardinality">
<code class="descname">get_cardinality</code><span class="sig-paren">(</span><em>node=None</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/MarkovModel.html#MarkovModel.get_cardinality"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.MarkovModel.MarkovModel.get_cardinality" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the cardinality of the node. If node is not specified returns
a dictionary with the given variable as keys and their respective cardinality
as values.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>node: any hashable python object (optional)</strong></p>
<blockquote class="last">
<div><p>The node whose cardinality we want. If node is not specified returns a
dictionary with the given variable as keys and their respective cardinality
as values.</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">MarkovModel</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.factors.discrete</span> <span class="k">import</span> <span class="n">DiscreteFactor</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">student</span> <span class="o">=</span> <span class="n">MarkovModel</span><span class="p">([(</span><span class="s1">&#39;Alice&#39;</span><span class="p">,</span> <span class="s1">&#39;Bob&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;Bob&#39;</span><span class="p">,</span> <span class="s1">&#39;Charles&#39;</span><span class="p">)])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">factor</span> <span class="o">=</span> <span class="n">DiscreteFactor</span><span class="p">([</span><span class="s1">&#39;Alice&#39;</span><span class="p">,</span> <span class="s1">&#39;Bob&#39;</span><span class="p">],</span> <span class="n">cardinality</span><span class="o">=</span><span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span>
<span class="gp">... </span>                <span class="n">values</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">rand</span><span class="p">(</span><span class="mi">4</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">student</span><span class="o">.</span><span class="n">add_factors</span><span class="p">(</span><span class="n">factor</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">student</span><span class="o">.</span><span class="n">get_cardinality</span><span class="p">(</span><span class="n">node</span><span class="o">=</span><span class="s1">&#39;Alice&#39;</span><span class="p">)</span>
<span class="go">2</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">student</span><span class="o">.</span><span class="n">get_cardinality</span><span class="p">()</span>
<span class="go">defaultdict(&lt;class &#39;int&#39;&gt;, {&#39;Bob&#39;: 2, &#39;Alice&#39;: 2})</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.MarkovModel.MarkovModel.get_factors">
<code class="descname">get_factors</code><span class="sig-paren">(</span><em>node=None</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/MarkovModel.html#MarkovModel.get_factors"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.MarkovModel.MarkovModel.get_factors" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns all the factors containing the node. If node is not specified
returns all the factors that have been added till now to the graph.</p>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">MarkovModel</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.factors.discrete</span> <span class="k">import</span> <span class="n">DiscreteFactor</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">student</span> <span class="o">=</span> <span class="n">MarkovModel</span><span class="p">([(</span><span class="s1">&#39;Alice&#39;</span><span class="p">,</span> <span class="s1">&#39;Bob&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;Bob&#39;</span><span class="p">,</span> <span class="s1">&#39;Charles&#39;</span><span class="p">)])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">factor1</span> <span class="o">=</span> <span class="n">DiscreteFactor</span><span class="p">([</span><span class="s1">&#39;Alice&#39;</span><span class="p">,</span> <span class="s1">&#39;Bob&#39;</span><span class="p">],</span> <span class="n">cardinality</span><span class="o">=</span><span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span>
<span class="gp">... </span>                <span class="n">values</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">rand</span><span class="p">(</span><span class="mi">4</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">factor2</span> <span class="o">=</span> <span class="n">DiscreteFactor</span><span class="p">([</span><span class="s1">&#39;Bob&#39;</span><span class="p">,</span> <span class="s1">&#39;Charles&#39;</span><span class="p">],</span> <span class="n">cardinality</span><span class="o">=</span><span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">],</span>
<span class="gp">... </span>                                    <span class="n">values</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">ones</span><span class="p">(</span><span class="mi">6</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">student</span><span class="o">.</span><span class="n">add_factors</span><span class="p">(</span><span class="n">factor1</span><span class="p">,</span><span class="n">factor2</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">student</span><span class="o">.</span><span class="n">get_factors</span><span class="p">()</span>
<span class="go">[&lt;DiscreteFactor representing phi(Alice:2, Bob:2) at 0x7f8a0e9bf630&gt;,</span>
<span class="go"> &lt;DiscreteFactor representing phi(Bob:2, Charles:3) at 0x7f8a0e9bf5f8&gt;]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">student</span><span class="o">.</span><span class="n">get_factors</span><span class="p">(</span><span class="s1">&#39;Alice&#39;</span><span class="p">)</span>
<span class="go">[&lt;DiscreteFactor representing phi(Alice:2, Bob:2) at 0x7f8a0e9bf630&gt;]</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.MarkovModel.MarkovModel.get_local_independencies">
<code class="descname">get_local_independencies</code><span class="sig-paren">(</span><em>latex=False</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/MarkovModel.html#MarkovModel.get_local_independencies"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.MarkovModel.MarkovModel.get_local_independencies" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns all the local independencies present in the markov model.</p>
<p>Local independencies are the independence assertion in the form of
.. math:: {X perp W - {X} - MB(X) | MB(X)}
where MB is the markov blanket of all the random variables in X</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>latex: boolean</strong></p>
<blockquote class="last">
<div><p>If latex=True then latex string of the indepedence assertion would
be created</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">MarkovModel</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">mm</span> <span class="o">=</span> <span class="n">MarkovModel</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">mm</span><span class="o">.</span><span class="n">add_nodes_from</span><span class="p">([</span><span class="s1">&#39;x1&#39;</span><span class="p">,</span> <span class="s1">&#39;x2&#39;</span><span class="p">,</span> <span class="s1">&#39;x3&#39;</span><span class="p">,</span> <span class="s1">&#39;x4&#39;</span><span class="p">,</span> <span class="s1">&#39;x5&#39;</span><span class="p">,</span> <span class="s1">&#39;x6&#39;</span><span class="p">,</span> <span class="s1">&#39;x7&#39;</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">mm</span><span class="o">.</span><span class="n">add_edges_from</span><span class="p">([(</span><span class="s1">&#39;x1&#39;</span><span class="p">,</span> <span class="s1">&#39;x3&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;x1&#39;</span><span class="p">,</span> <span class="s1">&#39;x4&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;x2&#39;</span><span class="p">,</span> <span class="s1">&#39;x4&#39;</span><span class="p">),</span>
<span class="gp">... </span>                   <span class="p">(</span><span class="s1">&#39;x2&#39;</span><span class="p">,</span> <span class="s1">&#39;x5&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;x3&#39;</span><span class="p">,</span> <span class="s1">&#39;x6&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;x4&#39;</span><span class="p">,</span> <span class="s1">&#39;x6&#39;</span><span class="p">),</span>
<span class="gp">... </span>                   <span class="p">(</span><span class="s1">&#39;x4&#39;</span><span class="p">,</span> <span class="s1">&#39;x7&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;x5&#39;</span><span class="p">,</span> <span class="s1">&#39;x7&#39;</span><span class="p">)])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">mm</span><span class="o">.</span><span class="n">get_local_independecies</span><span class="p">()</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.MarkovModel.MarkovModel.get_partition_function">
<code class="descname">get_partition_function</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/MarkovModel.html#MarkovModel.get_partition_function"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.MarkovModel.MarkovModel.get_partition_function" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the partition function for a given undirected graph.</p>
<p>A partition function is defined as</p>
<div class="math">
<p><img src="_images/math/e3022486d2a93cc2ab603fc68d4158edafd4263e.png" alt="\sum_{X}(\prod_{i=1}^{m} \phi_i)"/></p>
</div><p>where m is the number of factors present in the graph
and X are all the random variables present.</p>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">MarkovModel</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.factors.discrete</span> <span class="k">import</span> <span class="n">DiscreteFactor</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span> <span class="o">=</span> <span class="n">MarkovModel</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_nodes_from</span><span class="p">([</span><span class="s1">&#39;x1&#39;</span><span class="p">,</span> <span class="s1">&#39;x2&#39;</span><span class="p">,</span> <span class="s1">&#39;x3&#39;</span><span class="p">,</span> <span class="s1">&#39;x4&#39;</span><span class="p">,</span> <span class="s1">&#39;x5&#39;</span><span class="p">,</span> <span class="s1">&#39;x6&#39;</span><span class="p">,</span> <span class="s1">&#39;x7&#39;</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_edges_from</span><span class="p">([(</span><span class="s1">&#39;x1&#39;</span><span class="p">,</span> <span class="s1">&#39;x3&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;x1&#39;</span><span class="p">,</span> <span class="s1">&#39;x4&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;x2&#39;</span><span class="p">,</span> <span class="s1">&#39;x4&#39;</span><span class="p">),</span>
<span class="gp">... </span>                  <span class="p">(</span><span class="s1">&#39;x2&#39;</span><span class="p">,</span> <span class="s1">&#39;x5&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;x3&#39;</span><span class="p">,</span> <span class="s1">&#39;x6&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;x4&#39;</span><span class="p">,</span> <span class="s1">&#39;x6&#39;</span><span class="p">),</span>
<span class="gp">... </span>                  <span class="p">(</span><span class="s1">&#39;x4&#39;</span><span class="p">,</span> <span class="s1">&#39;x7&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;x5&#39;</span><span class="p">,</span> <span class="s1">&#39;x7&#39;</span><span class="p">)])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">phi</span> <span class="o">=</span> <span class="p">[</span><span class="n">DiscreteFactor</span><span class="p">(</span><span class="n">edge</span><span class="p">,</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">rand</span><span class="p">(</span><span class="mi">4</span><span class="p">))</span> <span class="k">for</span> <span class="n">edge</span> <span class="ow">in</span> <span class="n">G</span><span class="o">.</span><span class="n">edges</span><span class="p">()]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_factors</span><span class="p">(</span><span class="o">*</span><span class="n">phi</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">get_partition_function</span><span class="p">()</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.MarkovModel.MarkovModel.markov_blanket">
<code class="descname">markov_blanket</code><span class="sig-paren">(</span><em>node</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/MarkovModel.html#MarkovModel.markov_blanket"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.MarkovModel.MarkovModel.markov_blanket" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns a markov blanket for a random variable.</p>
<p>Markov blanket is the neighboring nodes of the given node.</p>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">MarkovModel</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">mm</span> <span class="o">=</span> <span class="n">MarkovModel</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">mm</span><span class="o">.</span><span class="n">add_nodes_from</span><span class="p">([</span><span class="s1">&#39;x1&#39;</span><span class="p">,</span> <span class="s1">&#39;x2&#39;</span><span class="p">,</span> <span class="s1">&#39;x3&#39;</span><span class="p">,</span> <span class="s1">&#39;x4&#39;</span><span class="p">,</span> <span class="s1">&#39;x5&#39;</span><span class="p">,</span> <span class="s1">&#39;x6&#39;</span><span class="p">,</span> <span class="s1">&#39;x7&#39;</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">mm</span><span class="o">.</span><span class="n">add_edges_from</span><span class="p">([(</span><span class="s1">&#39;x1&#39;</span><span class="p">,</span> <span class="s1">&#39;x3&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;x1&#39;</span><span class="p">,</span> <span class="s1">&#39;x4&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;x2&#39;</span><span class="p">,</span> <span class="s1">&#39;x4&#39;</span><span class="p">),</span>
<span class="gp">... </span>                   <span class="p">(</span><span class="s1">&#39;x2&#39;</span><span class="p">,</span> <span class="s1">&#39;x5&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;x3&#39;</span><span class="p">,</span> <span class="s1">&#39;x6&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;x4&#39;</span><span class="p">,</span> <span class="s1">&#39;x6&#39;</span><span class="p">),</span>
<span class="gp">... </span>                   <span class="p">(</span><span class="s1">&#39;x4&#39;</span><span class="p">,</span> <span class="s1">&#39;x7&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;x5&#39;</span><span class="p">,</span> <span class="s1">&#39;x7&#39;</span><span class="p">)])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">mm</span><span class="o">.</span><span class="n">markov_blanket</span><span class="p">(</span><span class="s1">&#39;x1&#39;</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.MarkovModel.MarkovModel.remove_factors">
<code class="descname">remove_factors</code><span class="sig-paren">(</span><em>*factors</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/MarkovModel.html#MarkovModel.remove_factors"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.MarkovModel.MarkovModel.remove_factors" title="Permalink to this definition">¶</a></dt>
<dd><p>Removes the given factors from the added factors.</p>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">MarkovModel</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.factors.discrete</span> <span class="k">import</span> <span class="n">DiscreteFactor</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">student</span> <span class="o">=</span> <span class="n">MarkovModel</span><span class="p">([(</span><span class="s1">&#39;Alice&#39;</span><span class="p">,</span> <span class="s1">&#39;Bob&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;Bob&#39;</span><span class="p">,</span> <span class="s1">&#39;Charles&#39;</span><span class="p">)])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">factor</span> <span class="o">=</span> <span class="n">DiscreteFactor</span><span class="p">([</span><span class="s1">&#39;Alice&#39;</span><span class="p">,</span> <span class="s1">&#39;Bob&#39;</span><span class="p">],</span> <span class="n">cardinality</span><span class="o">=</span><span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span>
<span class="gp">... </span>                <span class="n">values</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">rand</span><span class="p">(</span><span class="mi">4</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">student</span><span class="o">.</span><span class="n">add_factors</span><span class="p">(</span><span class="n">factor</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">student</span><span class="o">.</span><span class="n">remove_factors</span><span class="p">(</span><span class="n">factor</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.MarkovModel.MarkovModel.to_bayesian_model">
<code class="descname">to_bayesian_model</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/MarkovModel.html#MarkovModel.to_bayesian_model"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.MarkovModel.MarkovModel.to_bayesian_model" title="Permalink to this definition">¶</a></dt>
<dd><p>Creates a Bayesian Model which is a minimum I-Map for this markov model.</p>
<p>The ordering of parents may not remain constant. It would depend on the
ordering of variable in the junction tree (which is not constant) all the
time.</p>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">MarkovModel</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.factors.discrete</span> <span class="k">import</span> <span class="n">DiscreteFactor</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">mm</span> <span class="o">=</span> <span class="n">MarkovModel</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">mm</span><span class="o">.</span><span class="n">add_nodes_from</span><span class="p">([</span><span class="s1">&#39;x1&#39;</span><span class="p">,</span> <span class="s1">&#39;x2&#39;</span><span class="p">,</span> <span class="s1">&#39;x3&#39;</span><span class="p">,</span> <span class="s1">&#39;x4&#39;</span><span class="p">,</span> <span class="s1">&#39;x5&#39;</span><span class="p">,</span> <span class="s1">&#39;x6&#39;</span><span class="p">,</span> <span class="s1">&#39;x7&#39;</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">mm</span><span class="o">.</span><span class="n">add_edges_from</span><span class="p">([(</span><span class="s1">&#39;x1&#39;</span><span class="p">,</span> <span class="s1">&#39;x3&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;x1&#39;</span><span class="p">,</span> <span class="s1">&#39;x4&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;x2&#39;</span><span class="p">,</span> <span class="s1">&#39;x4&#39;</span><span class="p">),</span>
<span class="gp">... </span>                   <span class="p">(</span><span class="s1">&#39;x2&#39;</span><span class="p">,</span> <span class="s1">&#39;x5&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;x3&#39;</span><span class="p">,</span> <span class="s1">&#39;x6&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;x4&#39;</span><span class="p">,</span> <span class="s1">&#39;x6&#39;</span><span class="p">),</span>
<span class="gp">... </span>                   <span class="p">(</span><span class="s1">&#39;x4&#39;</span><span class="p">,</span> <span class="s1">&#39;x7&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;x5&#39;</span><span class="p">,</span> <span class="s1">&#39;x7&#39;</span><span class="p">)])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">phi</span> <span class="o">=</span> <span class="p">[</span><span class="n">DiscreteFactor</span><span class="p">(</span><span class="n">edge</span><span class="p">,</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">rand</span><span class="p">(</span><span class="mi">4</span><span class="p">))</span> <span class="k">for</span> <span class="n">edge</span> <span class="ow">in</span> <span class="n">mm</span><span class="o">.</span><span class="n">edges</span><span class="p">()]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">mm</span><span class="o">.</span><span class="n">add_factors</span><span class="p">(</span><span class="o">*</span><span class="n">phi</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">bm</span> <span class="o">=</span> <span class="n">mm</span><span class="o">.</span><span class="n">to_bayesian_model</span><span class="p">()</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.MarkovModel.MarkovModel.to_factor_graph">
<code class="descname">to_factor_graph</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/MarkovModel.html#MarkovModel.to_factor_graph"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.MarkovModel.MarkovModel.to_factor_graph" title="Permalink to this definition">¶</a></dt>
<dd><p>Converts the markov model into factor graph.</p>
<p>A factor graph contains two types of nodes. One type corresponds to
random variables whereas the second type corresponds to factors over
these variables. The graph only contains edges between variables and
factor nodes. Each factor node is associated with one factor whose
scope is the set of variables that are its neighbors.</p>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">MarkovModel</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.factors.discrete</span> <span class="k">import</span> <span class="n">DiscreteFactor</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">student</span> <span class="o">=</span> <span class="n">MarkovModel</span><span class="p">([(</span><span class="s1">&#39;Alice&#39;</span><span class="p">,</span> <span class="s1">&#39;Bob&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;Bob&#39;</span><span class="p">,</span> <span class="s1">&#39;Charles&#39;</span><span class="p">)])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">factor1</span> <span class="o">=</span> <span class="n">DiscreteFactor</span><span class="p">([</span><span class="s1">&#39;Alice&#39;</span><span class="p">,</span> <span class="s1">&#39;Bob&#39;</span><span class="p">],</span> <span class="p">[</span><span class="mi">3</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">rand</span><span class="p">(</span><span class="mi">6</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">factor2</span> <span class="o">=</span> <span class="n">DiscreteFactor</span><span class="p">([</span><span class="s1">&#39;Bob&#39;</span><span class="p">,</span> <span class="s1">&#39;Charles&#39;</span><span class="p">],</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">rand</span><span class="p">(</span><span class="mi">4</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">student</span><span class="o">.</span><span class="n">add_factors</span><span class="p">(</span><span class="n">factor1</span><span class="p">,</span> <span class="n">factor2</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">factor_graph</span> <span class="o">=</span> <span class="n">student</span><span class="o">.</span><span class="n">to_factor_graph</span><span class="p">()</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.MarkovModel.MarkovModel.to_junction_tree">
<code class="descname">to_junction_tree</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/MarkovModel.html#MarkovModel.to_junction_tree"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.MarkovModel.MarkovModel.to_junction_tree" title="Permalink to this definition">¶</a></dt>
<dd><p>Creates a junction tree (or clique tree) for a given markov model.</p>
<p>For a given markov model (H) a junction tree (G) is a graph
1. where each node in G corresponds to a maximal clique in H
2. each sepset in G separates the variables strictly on one side of the
edge to other.</p>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">MarkovModel</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.factors.discrete</span> <span class="k">import</span> <span class="n">DiscreteFactor</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">mm</span> <span class="o">=</span> <span class="n">MarkovModel</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">mm</span><span class="o">.</span><span class="n">add_nodes_from</span><span class="p">([</span><span class="s1">&#39;x1&#39;</span><span class="p">,</span> <span class="s1">&#39;x2&#39;</span><span class="p">,</span> <span class="s1">&#39;x3&#39;</span><span class="p">,</span> <span class="s1">&#39;x4&#39;</span><span class="p">,</span> <span class="s1">&#39;x5&#39;</span><span class="p">,</span> <span class="s1">&#39;x6&#39;</span><span class="p">,</span> <span class="s1">&#39;x7&#39;</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">mm</span><span class="o">.</span><span class="n">add_edges_from</span><span class="p">([(</span><span class="s1">&#39;x1&#39;</span><span class="p">,</span> <span class="s1">&#39;x3&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;x1&#39;</span><span class="p">,</span> <span class="s1">&#39;x4&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;x2&#39;</span><span class="p">,</span> <span class="s1">&#39;x4&#39;</span><span class="p">),</span>
<span class="gp">... </span>                   <span class="p">(</span><span class="s1">&#39;x2&#39;</span><span class="p">,</span> <span class="s1">&#39;x5&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;x3&#39;</span><span class="p">,</span> <span class="s1">&#39;x6&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;x4&#39;</span><span class="p">,</span> <span class="s1">&#39;x6&#39;</span><span class="p">),</span>
<span class="gp">... </span>                   <span class="p">(</span><span class="s1">&#39;x4&#39;</span><span class="p">,</span> <span class="s1">&#39;x7&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;x5&#39;</span><span class="p">,</span> <span class="s1">&#39;x7&#39;</span><span class="p">)])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">phi</span> <span class="o">=</span> <span class="p">[</span><span class="n">DiscreteFactor</span><span class="p">(</span><span class="n">edge</span><span class="p">,</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">rand</span><span class="p">(</span><span class="mi">4</span><span class="p">))</span> <span class="k">for</span> <span class="n">edge</span> <span class="ow">in</span> <span class="n">mm</span><span class="o">.</span><span class="n">edges</span><span class="p">()]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">mm</span><span class="o">.</span><span class="n">add_factors</span><span class="p">(</span><span class="o">*</span><span class="n">phi</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">junction_tree</span> <span class="o">=</span> <span class="n">mm</span><span class="o">.</span><span class="n">to_junction_tree</span><span class="p">()</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.MarkovModel.MarkovModel.triangulate">
<code class="descname">triangulate</code><span class="sig-paren">(</span><em>heuristic='H6'</em>, <em>order=None</em>, <em>inplace=False</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/MarkovModel.html#MarkovModel.triangulate"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.MarkovModel.MarkovModel.triangulate" title="Permalink to this definition">¶</a></dt>
<dd><p>Triangulate the graph.</p>
<p>If order of deletion is given heuristic algorithm will not be used.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>heuristic: H1 | H2 | H3 | H4 | H5 | H6</strong></p>
<blockquote>
<div><p>The heuristic algorithm to use to decide the deletion order of
the variables to compute the triangulated graph.
Let X be the set of variables and X(i) denotes the i-th variable.</p>
<ul class="simple">
<li>S(i) - The size of the clique created by deleting the variable.</li>
<li>E(i) - Cardinality of variable X(i).</li>
<li>M(i) - Maximum size of cliques given by X(i) and its adjacent nodes.</li>
<li>C(i) - Sum of size of cliques given by X(i) and its adjacent nodes.</li>
</ul>
<p>The heuristic algorithm decide the deletion order if this way:</p>
<ul class="simple">
<li>H1 - Delete the variable with minimal S(i).</li>
<li>H2 - Delete the variable with minimal S(i)/E(i).</li>
<li>H3 - Delete the variable with minimal S(i) - M(i).</li>
<li>H4 - Delete the variable with minimal S(i) - C(i).</li>
<li>H5 - Delete the variable with minimal S(i)/M(i).</li>
<li>H6 - Delete the variable with minimal S(i)/C(i).</li>
</ul>
</div></blockquote>
<p><strong>order: list, tuple (array-like)</strong></p>
<blockquote>
<div><p>The order of deletion of the variables to compute the triagulated
graph. If order is given heuristic algorithm will not be used.</p>
</div></blockquote>
<p><strong>inplace: True | False</strong></p>
<blockquote class="last">
<div><p>if inplace is true then adds the edges to the object from
which it is called else returns a new object.</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">MarkovModel</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.factors.discrete</span> <span class="k">import</span> <span class="n">DiscreteFactor</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span> <span class="o">=</span> <span class="n">MarkovModel</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_nodes_from</span><span class="p">([</span><span class="s1">&#39;x1&#39;</span><span class="p">,</span> <span class="s1">&#39;x2&#39;</span><span class="p">,</span> <span class="s1">&#39;x3&#39;</span><span class="p">,</span> <span class="s1">&#39;x4&#39;</span><span class="p">,</span> <span class="s1">&#39;x5&#39;</span><span class="p">,</span> <span class="s1">&#39;x6&#39;</span><span class="p">,</span> <span class="s1">&#39;x7&#39;</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_edges_from</span><span class="p">([(</span><span class="s1">&#39;x1&#39;</span><span class="p">,</span> <span class="s1">&#39;x3&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;x1&#39;</span><span class="p">,</span> <span class="s1">&#39;x4&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;x2&#39;</span><span class="p">,</span> <span class="s1">&#39;x4&#39;</span><span class="p">),</span>
<span class="gp">... </span>                  <span class="p">(</span><span class="s1">&#39;x2&#39;</span><span class="p">,</span> <span class="s1">&#39;x5&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;x3&#39;</span><span class="p">,</span> <span class="s1">&#39;x6&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;x4&#39;</span><span class="p">,</span> <span class="s1">&#39;x6&#39;</span><span class="p">),</span>
<span class="gp">... </span>                  <span class="p">(</span><span class="s1">&#39;x4&#39;</span><span class="p">,</span> <span class="s1">&#39;x7&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;x5&#39;</span><span class="p">,</span> <span class="s1">&#39;x7&#39;</span><span class="p">)])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">phi</span> <span class="o">=</span> <span class="p">[</span><span class="n">DiscreteFactor</span><span class="p">(</span><span class="n">edge</span><span class="p">,</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">rand</span><span class="p">(</span><span class="mi">4</span><span class="p">))</span> <span class="k">for</span> <span class="n">edge</span> <span class="ow">in</span> <span class="n">G</span><span class="o">.</span><span class="n">edges</span><span class="p">()]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_factors</span><span class="p">(</span><span class="o">*</span><span class="n">phi</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G_chordal</span> <span class="o">=</span> <span class="n">G</span><span class="o">.</span><span class="n">triangulate</span><span class="p">()</span>
</pre></div>
</div>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="module-pgmpy.models.FactorGraph">
<span id="factor-graph"></span><h2>Factor Graph<a class="headerlink" href="#module-pgmpy.models.FactorGraph" title="Permalink to this headline">¶</a></h2>
<dl class="class">
<dt id="pgmpy.models.FactorGraph.FactorGraph">
<em class="property">class </em><code class="descclassname">pgmpy.models.FactorGraph.</code><code class="descname">FactorGraph</code><span class="sig-paren">(</span><em>ebunch=None</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/FactorGraph.html#FactorGraph"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.FactorGraph.FactorGraph" title="Permalink to this definition">¶</a></dt>
<dd><p>Class for representing factor graph.</p>
<p>DiscreteFactor graph is a bipartite graph representing factorization of a function.
They allow efficient computation of marginal distributions through sum-product
algorithm.</p>
<p>A factor graph contains two types of nodes. One type corresponds to random
variables whereas the second type corresponds to factors over these variables.
The graph only contains edges between variables and factor nodes. Each factor
node is associated with one factor whose scope is the set of variables that
are its neighbors.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>data: input graph</strong></p>
<blockquote class="last">
<div><p>Data to initialize graph. If data=None (default) an empty graph is
created. The data is an edge list.</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<p>Create an empty FactorGraph with no nodes and no edges</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">FactorGraph</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span> <span class="o">=</span> <span class="n">FactorGraph</span><span class="p">()</span>
</pre></div>
</div>
<p>G can be grown by adding variable nodes as well as factor nodes</p>
<p><strong>Nodes:</strong></p>
<p>Add a node at a time or a list of nodes.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_node</span><span class="p">(</span><span class="s1">&#39;a&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_nodes_from</span><span class="p">([</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">phi1</span> <span class="o">=</span> <span class="n">DiscreteFactor</span><span class="p">([</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">],</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">rand</span><span class="p">(</span><span class="mi">4</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_factors</span><span class="p">(</span><span class="n">phi1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_nodes_from</span><span class="p">([</span><span class="n">phi1</span><span class="p">])</span>
</pre></div>
</div>
<p><strong>Edges:</strong></p>
<p>G can also be grown by adding edges.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_edge</span><span class="p">(</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="n">phi1</span><span class="p">)</span>
</pre></div>
</div>
<p>or a list of edges</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_edges_from</span><span class="p">([(</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="n">phi1</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="n">phi1</span><span class="p">)])</span>
</pre></div>
</div>
<dl class="method">
<dt id="pgmpy.models.FactorGraph.FactorGraph.add_edge">
<code class="descname">add_edge</code><span class="sig-paren">(</span><em>u</em>, <em>v</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/FactorGraph.html#FactorGraph.add_edge"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.FactorGraph.FactorGraph.add_edge" title="Permalink to this definition">¶</a></dt>
<dd><p>Add an edge between variable_node and factor_node.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>u, v: nodes</strong></p>
<blockquote class="last">
<div><p>Nodes can be any hashable Python object.</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">FactorGraph</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span> <span class="o">=</span> <span class="n">FactorGraph</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_nodes_from</span><span class="p">([</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="s1">&#39;c&#39;</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">phi1</span> <span class="o">=</span> <span class="n">DiscreteFactor</span><span class="p">([</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">],</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">rand</span><span class="p">(</span><span class="mi">4</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_nodes_from</span><span class="p">([</span><span class="n">phi1</span><span class="p">,</span> <span class="n">phi2</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_edge</span><span class="p">(</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="n">phi1</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.FactorGraph.FactorGraph.add_factors">
<code class="descname">add_factors</code><span class="sig-paren">(</span><em>*factors</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/FactorGraph.html#FactorGraph.add_factors"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.FactorGraph.FactorGraph.add_factors" title="Permalink to this definition">¶</a></dt>
<dd><p>Associate a factor to the graph.
See factors class for the order of potential values.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>*factor: pgmpy.factors.DiscreteFactor object</strong></p>
<blockquote class="last">
<div><p>A factor object on any subset of the variables of the model which
is to be associated with the model.</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">FactorGraph</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.factors.discrete</span> <span class="k">import</span> <span class="n">DiscreteFactor</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span> <span class="o">=</span> <span class="n">FactorGraph</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_nodes_from</span><span class="p">([</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="s1">&#39;c&#39;</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">phi1</span> <span class="o">=</span> <span class="n">DiscreteFactor</span><span class="p">([</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">],</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">rand</span><span class="p">(</span><span class="mi">4</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">phi2</span> <span class="o">=</span> <span class="n">DiscreteFactor</span><span class="p">([</span><span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="s1">&#39;c&#39;</span><span class="p">],</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">rand</span><span class="p">(</span><span class="mi">4</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_factors</span><span class="p">(</span><span class="n">phi1</span><span class="p">,</span> <span class="n">phi2</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_edges_from</span><span class="p">([(</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="n">phi1</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="n">phi1</span><span class="p">),</span>
<span class="gp">... </span>                  <span class="p">(</span><span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="n">phi2</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;c&#39;</span><span class="p">,</span> <span class="n">phi2</span><span class="p">)])</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.FactorGraph.FactorGraph.check_model">
<code class="descname">check_model</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/FactorGraph.html#FactorGraph.check_model"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.FactorGraph.FactorGraph.check_model" title="Permalink to this definition">¶</a></dt>
<dd><p>Check the model for various errors. This method checks for the following
errors. In the same time it also updates the cardinalities of all the
random variables.</p>
<ul class="simple">
<li>Check whether bipartite property of factor graph is still maintained
or not.</li>
<li>Check whether factors are associated for all the random variables or not.</li>
<li>Check if factors are defined for each factor node or not.</li>
<li>Check if cardinality information for all the variables is availble or not.</li>
<li>Check if cardinality of random variable remains same across all the
factors.</li>
</ul>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.FactorGraph.FactorGraph.copy">
<code class="descname">copy</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/FactorGraph.html#FactorGraph.copy"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.FactorGraph.FactorGraph.copy" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns a copy of the model.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body"><strong>FactorGraph</strong> : Copy of FactorGraph</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">FactorGraph</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.factors.discrete</span> <span class="k">import</span> <span class="n">DiscreteFactor</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span> <span class="o">=</span> <span class="n">FactorGraph</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_nodes_from</span><span class="p">([(</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="s1">&#39;c&#39;</span><span class="p">)])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">phi1</span> <span class="o">=</span> <span class="n">DiscreteFactor</span><span class="p">([</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">],</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">rand</span><span class="p">(</span><span class="mi">4</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">phi2</span> <span class="o">=</span> <span class="n">DiscreteFactor</span><span class="p">([</span><span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="s1">&#39;c&#39;</span><span class="p">],</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">rand</span><span class="p">(</span><span class="mi">4</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_factors</span><span class="p">(</span><span class="n">phi1</span><span class="p">,</span> <span class="n">phi2</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_nodes_from</span><span class="p">([</span><span class="n">phi1</span><span class="p">,</span> <span class="n">phi2</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_edges_from</span><span class="p">([(</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="n">phi1</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="n">phi1</span><span class="p">),</span>
<span class="gp">... </span>                  <span class="p">(</span><span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="n">phi2</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;c&#39;</span><span class="p">,</span> <span class="n">phi2</span><span class="p">)])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G_copy</span> <span class="o">=</span> <span class="n">G</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G_copy</span><span class="o">.</span><span class="n">nodes</span><span class="p">()</span>
<span class="go">[&lt;Factor representing phi(b:2, c:2) at 0xb4badd4c&gt;, &#39;b&#39;, &#39;c&#39;,</span>
<span class="go">  &#39;a&#39;, &lt;Factor representing phi(a:2, b:2) at 0xb4badf2c&gt;]</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.FactorGraph.FactorGraph.get_cardinality">
<code class="descname">get_cardinality</code><span class="sig-paren">(</span><em>node=None</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/FactorGraph.html#FactorGraph.get_cardinality"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.FactorGraph.FactorGraph.get_cardinality" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the cardinality of the node</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>node: any hashable python object (optional)</strong></p>
<blockquote>
<div><p>The node whose cardinality we want. If node is not specified returns a
dictionary with the given variable as keys and their respective cardinality
as values.</p>
</div></blockquote>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><strong>int or dict</strong> : If node is specified returns the cardinality of the node.</p>
<blockquote class="last">
<div><p>If node is not specified returns a dictionary with the given
variable as keys and their respective cardinality as values.</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">FactorGraph</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.factors</span> <span class="k">import</span> <span class="n">DiscreteFactor</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span> <span class="o">=</span> <span class="n">FactorGraph</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_nodes_from</span><span class="p">([</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="s1">&#39;c&#39;</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">phi1</span> <span class="o">=</span> <span class="n">DiscreteFactor</span><span class="p">([</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">],</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">rand</span><span class="p">(</span><span class="mi">4</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">phi2</span> <span class="o">=</span> <span class="n">DiscreteFactor</span><span class="p">([</span><span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="s1">&#39;c&#39;</span><span class="p">],</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">rand</span><span class="p">(</span><span class="mi">4</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_nodes_from</span><span class="p">([</span><span class="n">phi1</span><span class="p">,</span> <span class="n">phi2</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_edges_from</span><span class="p">([(</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="n">phi1</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="n">phi1</span><span class="p">),</span>
<span class="gp">... </span>                  <span class="p">(</span><span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="n">phi2</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;c&#39;</span><span class="p">,</span> <span class="n">phi2</span><span class="p">)])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_factors</span><span class="p">(</span><span class="n">phi1</span><span class="p">,</span> <span class="n">phi2</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">get_cardinality</span><span class="p">()</span>
<span class="go">    defaultdict(&lt;class &#39;int&#39;&gt;, {&#39;c&#39;: 2, &#39;b&#39;: 2, &#39;a&#39;: 2})</span>
</pre></div>
</div>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">get_cardinality</span><span class="p">(</span><span class="s1">&#39;a&#39;</span><span class="p">)</span>
<span class="go">    2</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.FactorGraph.FactorGraph.get_factor_nodes">
<code class="descname">get_factor_nodes</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/FactorGraph.html#FactorGraph.get_factor_nodes"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.FactorGraph.FactorGraph.get_factor_nodes" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns factors nodes present in the graph.</p>
<p>Before calling this method make sure that all the factors are added
properly.</p>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">FactorGraph</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.factors.discrete</span> <span class="k">import</span> <span class="n">DiscreteFactor</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span> <span class="o">=</span> <span class="n">FactorGraph</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_nodes_from</span><span class="p">([</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="s1">&#39;c&#39;</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">phi1</span> <span class="o">=</span> <span class="n">DiscreteFactor</span><span class="p">([</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">],</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">rand</span><span class="p">(</span><span class="mi">4</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">phi2</span> <span class="o">=</span> <span class="n">DiscreteFactor</span><span class="p">([</span><span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="s1">&#39;c&#39;</span><span class="p">],</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">rand</span><span class="p">(</span><span class="mi">4</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_nodes_from</span><span class="p">([</span><span class="n">phi1</span><span class="p">,</span> <span class="n">phi2</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_factors</span><span class="p">(</span><span class="n">phi1</span><span class="p">,</span> <span class="n">phi2</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_edges_from</span><span class="p">([(</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="n">phi1</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="n">phi1</span><span class="p">),</span>
<span class="gp">... </span>                  <span class="p">(</span><span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="n">phi2</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;c&#39;</span><span class="p">,</span> <span class="n">phi2</span><span class="p">)])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">get_factor_nodes</span><span class="p">()</span>
<span class="go">[&lt;DiscreteFactor representing phi(b:2, c:2) at 0x4b8c7f0&gt;,</span>
<span class="go"> &lt;DiscreteFactor representing phi(a:2, b:2) at 0x4b8c5b0&gt;]</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.FactorGraph.FactorGraph.get_factors">
<code class="descname">get_factors</code><span class="sig-paren">(</span><em>node=None</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/FactorGraph.html#FactorGraph.get_factors"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.FactorGraph.FactorGraph.get_factors" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the factors that have been added till now to the graph.</p>
<p>If node is not None, it would return the factor corresponding to the
given node.</p>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">FactorGraph</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.factors.discrete</span> <span class="k">import</span> <span class="n">DiscreteFactor</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span> <span class="o">=</span> <span class="n">FactorGraph</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_nodes_from</span><span class="p">([</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="s1">&#39;c&#39;</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">phi1</span> <span class="o">=</span> <span class="n">DiscreteFactor</span><span class="p">([</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">],</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">rand</span><span class="p">(</span><span class="mi">4</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">phi2</span> <span class="o">=</span> <span class="n">DiscreteFactor</span><span class="p">([</span><span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="s1">&#39;c&#39;</span><span class="p">],</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">rand</span><span class="p">(</span><span class="mi">4</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_factors</span><span class="p">(</span><span class="n">phi1</span><span class="p">,</span> <span class="n">phi2</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_nodes_from</span><span class="p">([</span><span class="n">phi1</span><span class="p">,</span> <span class="n">phi2</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_edges_from</span><span class="p">([(</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="n">phi1</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="n">phi1</span><span class="p">),</span>
<span class="gp">... </span>                  <span class="p">(</span><span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="n">phi2</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;c&#39;</span><span class="p">,</span> <span class="n">phi2</span><span class="p">)])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">get_factors</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">get_factors</span><span class="p">(</span><span class="n">node</span><span class="o">=</span><span class="n">phi1</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.FactorGraph.FactorGraph.get_partition_function">
<code class="descname">get_partition_function</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/FactorGraph.html#FactorGraph.get_partition_function"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.FactorGraph.FactorGraph.get_partition_function" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the partition function for a given undirected graph.</p>
<p>A partition function is defined as</p>
<div class="math">
<p><img src="_images/math/e3022486d2a93cc2ab603fc68d4158edafd4263e.png" alt="\sum_{X}(\prod_{i=1}^{m} \phi_i)"/></p>
</div><p>where m is the number of factors present in the graph
and X are all the random variables present.</p>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">FactorGraph</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.factors.discrete</span> <span class="k">import</span> <span class="n">DiscreteFactor</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span> <span class="o">=</span> <span class="n">FactorGraph</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_nodes_from</span><span class="p">([</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="s1">&#39;c&#39;</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">phi1</span> <span class="o">=</span> <span class="n">DiscreteFactor</span><span class="p">([</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">],</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">rand</span><span class="p">(</span><span class="mi">4</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">phi2</span> <span class="o">=</span> <span class="n">DiscreteFactor</span><span class="p">([</span><span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="s1">&#39;c&#39;</span><span class="p">],</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">rand</span><span class="p">(</span><span class="mi">4</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_factors</span><span class="p">(</span><span class="n">phi1</span><span class="p">,</span> <span class="n">phi2</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_nodes_from</span><span class="p">([</span><span class="n">phi1</span><span class="p">,</span> <span class="n">phi2</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_edges_from</span><span class="p">([(</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="n">phi1</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="n">phi1</span><span class="p">),</span>
<span class="gp">... </span>                  <span class="p">(</span><span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="n">phi2</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;c&#39;</span><span class="p">,</span> <span class="n">phi2</span><span class="p">)])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">get_factors</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">get_partition_function</span><span class="p">()</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.FactorGraph.FactorGraph.get_variable_nodes">
<code class="descname">get_variable_nodes</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/FactorGraph.html#FactorGraph.get_variable_nodes"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.FactorGraph.FactorGraph.get_variable_nodes" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns variable nodes present in the graph.</p>
<p>Before calling this method make sure that all the factors are added
properly.</p>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">FactorGraph</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.factors.discrete</span> <span class="k">import</span> <span class="n">DiscreteFactor</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span> <span class="o">=</span> <span class="n">FactorGraph</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_nodes_from</span><span class="p">([</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="s1">&#39;c&#39;</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">phi1</span> <span class="o">=</span> <span class="n">DiscreteFactor</span><span class="p">([</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">],</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">rand</span><span class="p">(</span><span class="mi">4</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">phi2</span> <span class="o">=</span> <span class="n">DiscreteFactor</span><span class="p">([</span><span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="s1">&#39;c&#39;</span><span class="p">],</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">rand</span><span class="p">(</span><span class="mi">4</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_nodes_from</span><span class="p">([</span><span class="n">phi1</span><span class="p">,</span> <span class="n">phi2</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_factors</span><span class="p">(</span><span class="n">phi1</span><span class="p">,</span> <span class="n">phi2</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_edges_from</span><span class="p">([(</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="n">phi1</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="n">phi1</span><span class="p">),</span>
<span class="gp">... </span>                  <span class="p">(</span><span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="n">phi2</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;c&#39;</span><span class="p">,</span> <span class="n">phi2</span><span class="p">)])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">get_variable_nodes</span><span class="p">()</span>
<span class="go">[&#39;a&#39;, &#39;b&#39;]</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.FactorGraph.FactorGraph.remove_factors">
<code class="descname">remove_factors</code><span class="sig-paren">(</span><em>*factors</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/FactorGraph.html#FactorGraph.remove_factors"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.FactorGraph.FactorGraph.remove_factors" title="Permalink to this definition">¶</a></dt>
<dd><p>Removes the given factors from the added factors.</p>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">FactorGraph</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.factors.discrete</span> <span class="k">import</span> <span class="n">DiscreteFactor</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span> <span class="o">=</span> <span class="n">FactorGraph</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_nodes_from</span><span class="p">([</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="s1">&#39;c&#39;</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">phi1</span> <span class="o">=</span> <span class="n">DiscreteFactor</span><span class="p">([</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">],</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">rand</span><span class="p">(</span><span class="mi">4</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_factors</span><span class="p">(</span><span class="n">phi1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">remove_factors</span><span class="p">(</span><span class="n">phi1</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.FactorGraph.FactorGraph.to_junction_tree">
<code class="descname">to_junction_tree</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/FactorGraph.html#FactorGraph.to_junction_tree"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.FactorGraph.FactorGraph.to_junction_tree" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a junction treeo (or clique tree) for a given factor graph.</p>
<p>For a given factor graph (H) a junction tree (G) is a graph
1. where each node in G corresponds to a maximal clique in H
2. each sepset in G separates the variables strictly on one side of
edge to other</p>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">FactorGraph</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.factors.discrete</span> <span class="k">import</span> <span class="n">DiscreteFactor</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span> <span class="o">=</span> <span class="n">FactorGraph</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_nodes_from</span><span class="p">([</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="s1">&#39;c&#39;</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">phi1</span> <span class="o">=</span> <span class="n">DiscreteFactor</span><span class="p">([</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">],</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">rand</span><span class="p">(</span><span class="mi">4</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">phi2</span> <span class="o">=</span> <span class="n">DiscreteFactor</span><span class="p">([</span><span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="s1">&#39;c&#39;</span><span class="p">],</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">rand</span><span class="p">(</span><span class="mi">4</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_factors</span><span class="p">(</span><span class="n">phi1</span><span class="p">,</span> <span class="n">phi2</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_nodes_from</span><span class="p">([</span><span class="n">phi1</span><span class="p">,</span> <span class="n">phi2</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_edges_from</span><span class="p">([(</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="n">phi1</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="n">phi1</span><span class="p">),</span>
<span class="gp">... </span>                  <span class="p">(</span><span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="n">phi2</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;c&#39;</span><span class="p">,</span> <span class="n">phi2</span><span class="p">)])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">mm</span> <span class="o">=</span> <span class="n">G</span><span class="o">.</span><span class="n">to_markov_model</span><span class="p">()</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.FactorGraph.FactorGraph.to_markov_model">
<code class="descname">to_markov_model</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/FactorGraph.html#FactorGraph.to_markov_model"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.FactorGraph.FactorGraph.to_markov_model" title="Permalink to this definition">¶</a></dt>
<dd><p>Converts the factor graph into markov model.</p>
<p>A markov model contains nodes as random variables and edge between
two nodes imply interaction between them.</p>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">FactorGraph</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.factors.discrete</span> <span class="k">import</span> <span class="n">DiscreteFactor</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span> <span class="o">=</span> <span class="n">FactorGraph</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_nodes_from</span><span class="p">([</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="s1">&#39;c&#39;</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">phi1</span> <span class="o">=</span> <span class="n">DiscreteFactor</span><span class="p">([</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">],</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">rand</span><span class="p">(</span><span class="mi">4</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">phi2</span> <span class="o">=</span> <span class="n">DiscreteFactor</span><span class="p">([</span><span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="s1">&#39;c&#39;</span><span class="p">],</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">rand</span><span class="p">(</span><span class="mi">4</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_factors</span><span class="p">(</span><span class="n">phi1</span><span class="p">,</span> <span class="n">phi2</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_nodes_from</span><span class="p">([</span><span class="n">phi1</span><span class="p">,</span> <span class="n">phi2</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_edges_from</span><span class="p">([(</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="n">phi1</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="n">phi1</span><span class="p">),</span>
<span class="gp">... </span>                  <span class="p">(</span><span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="n">phi2</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;c&#39;</span><span class="p">,</span> <span class="n">phi2</span><span class="p">)])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">mm</span> <span class="o">=</span> <span class="n">G</span><span class="o">.</span><span class="n">to_markov_model</span><span class="p">()</span>
</pre></div>
</div>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="module-pgmpy.models.ClusterGraph">
<span id="cluster-graph"></span><h2>Cluster Graph<a class="headerlink" href="#module-pgmpy.models.ClusterGraph" title="Permalink to this headline">¶</a></h2>
<dl class="class">
<dt id="pgmpy.models.ClusterGraph.ClusterGraph">
<em class="property">class </em><code class="descclassname">pgmpy.models.ClusterGraph.</code><code class="descname">ClusterGraph</code><span class="sig-paren">(</span><em>ebunch=None</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/ClusterGraph.html#ClusterGraph"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.ClusterGraph.ClusterGraph" title="Permalink to this definition">¶</a></dt>
<dd><p>Base class for representing Cluster Graph.</p>
<p>Cluster graph is an undirected graph which is associated with a subset of variables. The graph contains undirected
edges that connects clusters whose scopes have a non-empty intersection.</p>
<p>Formally, a cluster graph is  <img class="math" src="_images/math/1714943229d8b9c42025f70efdc14803661b6cc0.png" alt="\mathcal{U}"/> for a set of factors <img class="math" src="_images/math/e486de19dbb61c9a63584f6e4ddd6e92ef03d665.png" alt="\Phi"/> over <img class="math" src="_images/math/343a944b6a22dc1a14dfecd2ef0d255012e38380.png" alt="\mathcal{X}"/> is an
undirected graph, each of whose nodes <img class="math" src="_images/math/df0deb143e5ac127f00bd248ee8001ecae572adc.png" alt="i"/> is associated with a subset <img class="math" src="_images/math/0f9a08b01e9d81e24c297f7166649624ed5ebc30.png" alt="C_i \subseteq X"/>. A cluster
graph must be family-preserving - each factor <img class="math" src="_images/math/ac12710c1fdf2eef0c0c1c5c99f0156b7db18a35.png" alt="\phi \in \Phi"/> must be associated with a cluster C, denoted
<img class="math" src="_images/math/1d371ab7a5f634ee8acc85e6f1b1e129769ad8c5.png" alt="\alpha(\phi)"/>, such that <img class="math" src="_images/math/486f4dbdb67ae8afb5bae7e089c41e52a75df18f.png" alt="Scope[\phi] \subseteq C_i"/>. Each edge between a pair of clusters <img class="math" src="_images/math/1c63a29a39682e328e860198029d2c555613afd1.png" alt="C_i"/>
and <img class="math" src="_images/math/838b34ee8845abed9d2c6f778df9387eecd350b4.png" alt="C_j"/> is associated with a sepset <img class="math" src="_images/math/e6baf8cc8e8694ad13bcee5f252f2b08438c50d6.png" alt="S_{i,j} \subseteq C_i \cap C_j"/>.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>data: input graph</strong></p>
<blockquote class="last">
<div><p>Data to initialize graph. If data=None (default) an empty graph is created. The data is an edge list</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<p>Create an empty ClusterGraph with no nodes and no edges</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">ClusterGraph</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span> <span class="o">=</span> <span class="n">ClusterGraph</span><span class="p">()</span>
</pre></div>
</div>
<p>G can be grown by adding clique nodes.</p>
<p><strong>Nodes:</strong></p>
<p>Add a tuple (or list or set) of nodes as single clique node.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_node</span><span class="p">((</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="s1">&#39;c&#39;</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_nodes_from</span><span class="p">([(</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="s1">&#39;c&#39;</span><span class="p">)])</span>
</pre></div>
</div>
<p><strong>Edges:</strong></p>
<p>G can also be grown by adding edges.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_edge</span><span class="p">((</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="s1">&#39;c&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">))</span>
</pre></div>
</div>
<p>or a list of edges</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_edges_from</span><span class="p">([((</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="s1">&#39;c&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">)),</span>
<span class="gp">... </span>                  <span class="p">((</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="s1">&#39;c&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;c&#39;</span><span class="p">))])</span>
</pre></div>
</div>
<dl class="method">
<dt id="pgmpy.models.ClusterGraph.ClusterGraph.add_edge">
<code class="descname">add_edge</code><span class="sig-paren">(</span><em>u</em>, <em>v</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/ClusterGraph.html#ClusterGraph.add_edge"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.ClusterGraph.ClusterGraph.add_edge" title="Permalink to this definition">¶</a></dt>
<dd><p>Add an edge between two clique nodes.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>u, v: nodes</strong></p>
<blockquote class="last">
<div><p>Nodes can be any list or set or tuple of nodes forming a clique.</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">ClusterGraph</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span> <span class="o">=</span> <span class="n">ClusterGraph</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_nodes_from</span><span class="p">([(</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="s1">&#39;c&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;c&#39;</span><span class="p">)])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_edges_from</span><span class="p">([((</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="s1">&#39;c&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">)),</span>
<span class="gp">... </span>                  <span class="p">((</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="s1">&#39;c&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;c&#39;</span><span class="p">))])</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.ClusterGraph.ClusterGraph.add_factors">
<code class="descname">add_factors</code><span class="sig-paren">(</span><em>*factors</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/ClusterGraph.html#ClusterGraph.add_factors"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.ClusterGraph.ClusterGraph.add_factors" title="Permalink to this definition">¶</a></dt>
<dd><p>Associate a factor to the graph.
See factors class for the order of potential values</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>*factor: pgmpy.factors.factors object</strong></p>
<blockquote>
<div><p>A factor object on any subset of the variables of the model which
is to be associated with the model.</p>
</div></blockquote>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">None</p>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">ClusterGraph</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.factors.discrete</span> <span class="k">import</span> <span class="n">DiscreteFactor</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">student</span> <span class="o">=</span> <span class="n">ClusterGraph</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">student</span><span class="o">.</span><span class="n">add_node</span><span class="p">((</span><span class="s1">&#39;Alice&#39;</span><span class="p">,</span> <span class="s1">&#39;Bob&#39;</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">factor</span> <span class="o">=</span> <span class="n">DiscreteFactor</span><span class="p">([</span><span class="s1">&#39;Alice&#39;</span><span class="p">,</span> <span class="s1">&#39;Bob&#39;</span><span class="p">],</span> <span class="n">cardinality</span><span class="o">=</span><span class="p">[</span><span class="mi">3</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span>
<span class="gp">... </span>                <span class="n">values</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">rand</span><span class="p">(</span><span class="mi">6</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">student</span><span class="o">.</span><span class="n">add_factors</span><span class="p">(</span><span class="n">factor</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.ClusterGraph.ClusterGraph.add_node">
<code class="descname">add_node</code><span class="sig-paren">(</span><em>node</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/ClusterGraph.html#ClusterGraph.add_node"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.ClusterGraph.ClusterGraph.add_node" title="Permalink to this definition">¶</a></dt>
<dd><p>Add a single node to the cluster graph.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>node: node</strong></p>
<blockquote class="last">
<div><p>A node should be a collection of nodes forming a clique. It can be
a list, set or tuple of nodes</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">ClusterGraph</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span> <span class="o">=</span> <span class="n">ClusterGraph</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_node</span><span class="p">((</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="s1">&#39;c&#39;</span><span class="p">))</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.ClusterGraph.ClusterGraph.add_nodes_from">
<code class="descname">add_nodes_from</code><span class="sig-paren">(</span><em>nodes</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/ClusterGraph.html#ClusterGraph.add_nodes_from"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.ClusterGraph.ClusterGraph.add_nodes_from" title="Permalink to this definition">¶</a></dt>
<dd><p>Add multiple nodes to the cluster graph.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>nodes: iterable container</strong></p>
<blockquote class="last">
<div><p>A container of nodes (list, dict, set, etc.).</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">ClusterGraph</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span> <span class="o">=</span> <span class="n">ClusterGraph</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_nodes_from</span><span class="p">([(</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="s1">&#39;c&#39;</span><span class="p">)])</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.ClusterGraph.ClusterGraph.check_model">
<code class="descname">check_model</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/ClusterGraph.html#ClusterGraph.check_model"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.ClusterGraph.ClusterGraph.check_model" title="Permalink to this definition">¶</a></dt>
<dd><p>Check the model for various errors. This method checks for the following
errors.</p>
<ul class="simple">
<li>Checks if factors are defined for all the cliques or not.</li>
<li>Check for running intersection property is not done explicitly over
here as it done in the add_edges method.</li>
<li>Checks if cardinality information for all the variables is availble or not. If
not it raises an error.</li>
<li>Check if cardinality of random variable remains same across all the
factors.</li>
</ul>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">check: boolean</p>
<blockquote class="last">
<div><p>True if all the checks are passed</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.ClusterGraph.ClusterGraph.copy">
<code class="descname">copy</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/ClusterGraph.html#ClusterGraph.copy"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.ClusterGraph.ClusterGraph.copy" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns a copy of ClusterGraph.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">ClusterGraph: copy of ClusterGraph</p>
<p>Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.factors.discrete</span> <span class="k">import</span> <span class="n">DiscreteFactor</span>
</pre></div>
</div>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">G</span> <span class="o">=</span> <span class="n">ClusterGraph</span><span class="p">()</span>
</pre></div>
</div>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_nodes_from</span><span class="p">([(</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="s1">&#39;c&#39;</span><span class="p">)])</span>
</pre></div>
</div>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_edge</span><span class="p">((</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="s1">&#39;c&#39;</span><span class="p">))</span>
</pre></div>
</div>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">phi1</span> <span class="o">=</span> <span class="n">DiscreteFactor</span><span class="p">([</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">],</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">rand</span><span class="p">(</span><span class="mi">4</span><span class="p">))</span>
</pre></div>
</div>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">phi2</span> <span class="o">=</span> <span class="n">DiscreteFactor</span><span class="p">([</span><span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="s1">&#39;c&#39;</span><span class="p">],</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">rand</span><span class="p">(</span><span class="mi">4</span><span class="p">))</span>
</pre></div>
</div>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_factors</span><span class="p">(</span><span class="n">phi1</span><span class="p">,</span> <span class="n">phi2</span><span class="p">)</span>
</pre></div>
</div>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">graph_copy</span> <span class="o">=</span> <span class="n">G</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
</pre></div>
</div>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">graph_copy</span><span class="o">.</span><span class="n">factors</span>
</pre></div>
</div>
<p>[&lt;DiscreteFactor representing phi(a:2, b:2) at 0xb71b19cc&gt;,</p>
<blockquote>
<div><p>&lt;DiscreteFactor representing phi(b:2, c:2) at 0xb4eaf3ac&gt;]</p>
</div></blockquote>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">graph_copy</span><span class="o">.</span><span class="n">edges</span><span class="p">()</span>
</pre></div>
</div>
<p>[((&#8216;a&#8217;, &#8216;b&#8217;), (&#8216;b&#8217;, &#8216;c&#8217;))]</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">graph_copy</span><span class="o">.</span><span class="n">nodes</span><span class="p">()</span>
</pre></div>
</div>
<p class="last">[(&#8216;a&#8217;, &#8216;b&#8217;), (&#8216;b&#8217;, &#8216;c&#8217;)]</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.ClusterGraph.ClusterGraph.get_cardinality">
<code class="descname">get_cardinality</code><span class="sig-paren">(</span><em>node=None</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/ClusterGraph.html#ClusterGraph.get_cardinality"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.ClusterGraph.ClusterGraph.get_cardinality" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the cardinality of the node</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>node: any hashable python object (optional)</strong></p>
<blockquote>
<div><p>The node whose cardinality we want. If node is not specified returns a
dictionary with the given variable as keys and their respective cardinality
as values.</p>
</div></blockquote>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><strong>int or dict</strong> : If node is specified returns the cardinality of the node.</p>
<blockquote class="last">
<div><p>If node is not specified returns a dictionary with the given
variable as keys and their respective cardinality as values.</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">ClusterGraph</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.factors.discrete</span> <span class="k">import</span> <span class="n">DiscreteFactor</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">student</span> <span class="o">=</span> <span class="n">ClusterGraph</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">factor</span> <span class="o">=</span> <span class="n">DiscreteFactor</span><span class="p">([</span><span class="s1">&#39;Alice&#39;</span><span class="p">,</span> <span class="s1">&#39;Bob&#39;</span><span class="p">],</span> <span class="n">cardinality</span><span class="o">=</span><span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span>
<span class="gp">... </span>                <span class="n">values</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">rand</span><span class="p">(</span><span class="mi">4</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">student</span><span class="o">.</span><span class="n">add_node</span><span class="p">((</span><span class="s1">&#39;Alice&#39;</span><span class="p">,</span> <span class="s1">&#39;Bob&#39;</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">student</span><span class="o">.</span><span class="n">add_factors</span><span class="p">(</span><span class="n">factor</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">student</span><span class="o">.</span><span class="n">get_cardinality</span><span class="p">()</span>
<span class="go">defaultdict(&lt;class &#39;int&#39;&gt;, {&#39;Bob&#39;: 2, &#39;Alice&#39;: 2})</span>
</pre></div>
</div>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">student</span><span class="o">.</span><span class="n">get_cardinality</span><span class="p">(</span><span class="n">node</span><span class="o">=</span><span class="s1">&#39;Alice&#39;</span><span class="p">)</span>
<span class="go">2</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.ClusterGraph.ClusterGraph.get_factors">
<code class="descname">get_factors</code><span class="sig-paren">(</span><em>node=None</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/ClusterGraph.html#ClusterGraph.get_factors"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.ClusterGraph.ClusterGraph.get_factors" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the factors that have been added till now to the graph.</p>
<p>If node is not None, it would return the factor corresponding to the
given node.</p>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">ClusterGraph</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.factors.discrete</span> <span class="k">import</span> <span class="n">DiscreteFactor</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span> <span class="o">=</span> <span class="n">ClusterGraph</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_nodes_from</span><span class="p">([(</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="s1">&#39;c&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;c&#39;</span><span class="p">)])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_edges_from</span><span class="p">([((</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="s1">&#39;c&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">)),</span>
<span class="gp">... </span>                  <span class="p">((</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="s1">&#39;c&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;c&#39;</span><span class="p">))])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">phi1</span> <span class="o">=</span> <span class="n">DiscreteFactor</span><span class="p">([</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="s1">&#39;c&#39;</span><span class="p">],</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">rand</span><span class="p">(</span><span class="mi">8</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">phi2</span> <span class="o">=</span> <span class="n">DiscreteFactor</span><span class="p">([</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">],</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">rand</span><span class="p">(</span><span class="mi">4</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">phi3</span> <span class="o">=</span> <span class="n">DiscreteFactor</span><span class="p">([</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;c&#39;</span><span class="p">],</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">rand</span><span class="p">(</span><span class="mi">4</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_factors</span><span class="p">(</span><span class="n">phi1</span><span class="p">,</span> <span class="n">phi2</span><span class="p">,</span> <span class="n">phi3</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">get_factors</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">get_factors</span><span class="p">(</span><span class="n">node</span><span class="o">=</span><span class="p">(</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="s1">&#39;c&#39;</span><span class="p">))</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.ClusterGraph.ClusterGraph.get_partition_function">
<code class="descname">get_partition_function</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/ClusterGraph.html#ClusterGraph.get_partition_function"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.ClusterGraph.ClusterGraph.get_partition_function" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the partition function for a given undirected graph.</p>
<p>A partition function is defined as</p>
<div class="math">
<p><img src="_images/math/e3022486d2a93cc2ab603fc68d4158edafd4263e.png" alt="\sum_{X}(\prod_{i=1}^{m} \phi_i)"/></p>
</div><p>where m is the number of factors present in the graph
and X are all the random variables present.</p>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">ClusterGraph</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.factors.discrete</span> <span class="k">import</span> <span class="n">DiscreteFactor</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span> <span class="o">=</span> <span class="n">ClusterGraph</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_nodes_from</span><span class="p">([(</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="s1">&#39;c&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;c&#39;</span><span class="p">)])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_edges_from</span><span class="p">([((</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="s1">&#39;c&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">)),</span>
<span class="gp">... </span>                  <span class="p">((</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="s1">&#39;c&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;c&#39;</span><span class="p">))])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">phi1</span> <span class="o">=</span> <span class="n">DiscreteFactor</span><span class="p">([</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="s1">&#39;c&#39;</span><span class="p">],</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">rand</span><span class="p">(</span><span class="mi">8</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">phi2</span> <span class="o">=</span> <span class="n">DiscreteFactor</span><span class="p">([</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">],</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">rand</span><span class="p">(</span><span class="mi">4</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">phi3</span> <span class="o">=</span> <span class="n">DiscreteFactor</span><span class="p">([</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;c&#39;</span><span class="p">],</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">rand</span><span class="p">(</span><span class="mi">4</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_factors</span><span class="p">(</span><span class="n">phi1</span><span class="p">,</span> <span class="n">phi2</span><span class="p">,</span> <span class="n">phi3</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">get_partition_function</span><span class="p">()</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.ClusterGraph.ClusterGraph.remove_factors">
<code class="descname">remove_factors</code><span class="sig-paren">(</span><em>*factors</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/ClusterGraph.html#ClusterGraph.remove_factors"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.ClusterGraph.ClusterGraph.remove_factors" title="Permalink to this definition">¶</a></dt>
<dd><p>Removes the given factors from the added factors.</p>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">ClusterGraph</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.factors.discrete</span> <span class="k">import</span> <span class="n">DiscreteFactor</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">student</span> <span class="o">=</span> <span class="n">ClusterGraph</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">factor</span> <span class="o">=</span> <span class="n">DiscreteFactor</span><span class="p">([</span><span class="s1">&#39;Alice&#39;</span><span class="p">,</span> <span class="s1">&#39;Bob&#39;</span><span class="p">],</span> <span class="n">cardinality</span><span class="o">=</span><span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span>
<span class="gp">... </span>                <span class="n">value</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">rand</span><span class="p">(</span><span class="mi">4</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">student</span><span class="o">.</span><span class="n">add_factors</span><span class="p">(</span><span class="n">factor</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">student</span><span class="o">.</span><span class="n">remove_factors</span><span class="p">(</span><span class="n">factor</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="module-pgmpy.models.JunctionTree">
<span id="junction-tree"></span><h2>Junction Tree<a class="headerlink" href="#module-pgmpy.models.JunctionTree" title="Permalink to this headline">¶</a></h2>
<dl class="class">
<dt id="pgmpy.models.JunctionTree.JunctionTree">
<em class="property">class </em><code class="descclassname">pgmpy.models.JunctionTree.</code><code class="descname">JunctionTree</code><span class="sig-paren">(</span><em>ebunch=None</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/JunctionTree.html#JunctionTree"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.JunctionTree.JunctionTree" title="Permalink to this definition">¶</a></dt>
<dd><p>Class for representing Junction Tree.</p>
<p>Junction tree is undirected graph where each node represents a clique
(list, tuple or set of nodes) and edges represent sepset between two cliques.
Each sepset in G separates the variables strictly on one side of edge to
other.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>data: input graph</strong></p>
<blockquote class="last">
<div><p>Data to initialize graph. If data=None (default) an empty graph is
created. The data is an edge list.</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<p>Create an empty JunctionTree with no nodes and no edges</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">JunctionTree</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span> <span class="o">=</span> <span class="n">JunctionTree</span><span class="p">()</span>
</pre></div>
</div>
<p>G can be grown by adding clique nodes.</p>
<p><strong>Nodes:</strong></p>
<p>Add a tuple (or list or set) of nodes as single clique node.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_node</span><span class="p">((</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="s1">&#39;c&#39;</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_nodes_from</span><span class="p">([(</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="s1">&#39;c&#39;</span><span class="p">)])</span>
</pre></div>
</div>
<p><strong>Edges:</strong></p>
<p>G can also be grown by adding edges.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_edge</span><span class="p">((</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="s1">&#39;c&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">))</span>
</pre></div>
</div>
<p>or a list of edges</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_edges_from</span><span class="p">([((</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="s1">&#39;c&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">)),</span>
<span class="gp">... </span>                  <span class="p">((</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="s1">&#39;c&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;c&#39;</span><span class="p">))])</span>
</pre></div>
</div>
<dl class="method">
<dt id="pgmpy.models.JunctionTree.JunctionTree.add_edge">
<code class="descname">add_edge</code><span class="sig-paren">(</span><em>u</em>, <em>v</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/JunctionTree.html#JunctionTree.add_edge"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.JunctionTree.JunctionTree.add_edge" title="Permalink to this definition">¶</a></dt>
<dd><p>Add an edge between two clique nodes.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>u, v: nodes</strong></p>
<blockquote class="last">
<div><p>Nodes can be any list or set or tuple of nodes forming a clique.</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">JunctionTree</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span> <span class="o">=</span> <span class="n">JunctionTree</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_nodes_from</span><span class="p">([(</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="s1">&#39;c&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;c&#39;</span><span class="p">)])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_edges_from</span><span class="p">([((</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="s1">&#39;c&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">)),</span>
<span class="gp">... </span>                  <span class="p">((</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="s1">&#39;c&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;c&#39;</span><span class="p">))])</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.JunctionTree.JunctionTree.check_model">
<code class="descname">check_model</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/JunctionTree.html#JunctionTree.check_model"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.JunctionTree.JunctionTree.check_model" title="Permalink to this definition">¶</a></dt>
<dd><p>Check the model for various errors. This method checks for the following
errors. In the same time also updates the cardinalities of all the random
variables.</p>
<ul class="simple">
<li>Checks if clique potentials are defined for all the cliques or not.</li>
<li>Check for running intersection property is not done explicitly over
here as it done in the add_edges method.</li>
</ul>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">check: boolean</p>
<blockquote class="last">
<div><p>True if all the checks are passed</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.JunctionTree.JunctionTree.copy">
<code class="descname">copy</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/JunctionTree.html#JunctionTree.copy"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.JunctionTree.JunctionTree.copy" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns a copy of JunctionTree.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body"><strong>JunctionTree</strong> : copy of JunctionTree</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.factors.discrete</span> <span class="k">import</span> <span class="n">DiscreteFactor</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">JunctionTree</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span> <span class="o">=</span> <span class="n">JunctionTree</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_edges_from</span><span class="p">([((</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="s1">&#39;c&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">)),</span> <span class="p">((</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="s1">&#39;c&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;c&#39;</span><span class="p">))])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">phi1</span> <span class="o">=</span> <span class="n">DiscreteFactor</span><span class="p">([</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">],</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">rand</span><span class="p">(</span><span class="mi">2</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">phi2</span> <span class="o">=</span> <span class="n">DiscreteFactor</span><span class="p">([</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;c&#39;</span><span class="p">],</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">rand</span><span class="p">(</span><span class="mi">2</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_factors</span><span class="p">(</span><span class="n">phi1</span><span class="p">,</span><span class="n">phi2</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">modelCopy</span> <span class="o">=</span> <span class="n">G</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">modelCopy</span><span class="o">.</span><span class="n">edges</span><span class="p">()</span>
<span class="go">[((&#39;a&#39;, &#39;b&#39;), (&#39;a&#39;, &#39;b&#39;, &#39;c&#39;)), ((&#39;a&#39;, &#39;c&#39;), (&#39;a&#39;, &#39;b&#39;, &#39;c&#39;))]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">factors</span>
<span class="go">[&lt;DiscreteFactor representing phi(a:1, b:2) at 0xb720ee4c&gt;,</span>
<span class="go"> &lt;DiscreteFactor representing phi(a:1, c:2) at 0xb4e1e06c&gt;]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">modelCopy</span><span class="o">.</span><span class="n">factors</span>
<span class="go">[&lt;DiscreteFactor representing phi(a:1, b:2) at 0xb4bd11ec&gt;,</span>
<span class="go"> &lt;DiscreteFactor representing phi(a:1, c:2) at 0xb4bd138c&gt;]</span>
</pre></div>
</div>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="module-pgmpy.models.MarkovChain">
<span id="markov-chain"></span><h2>Markov Chain<a class="headerlink" href="#module-pgmpy.models.MarkovChain" title="Permalink to this headline">¶</a></h2>
<dl class="class">
<dt id="pgmpy.models.MarkovChain.MarkovChain">
<em class="property">class </em><code class="descclassname">pgmpy.models.MarkovChain.</code><code class="descname">MarkovChain</code><span class="sig-paren">(</span><em>variables=None</em>, <em>card=None</em>, <em>start_state=None</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/MarkovChain.html#MarkovChain"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.MarkovChain.MarkovChain" title="Permalink to this definition">¶</a></dt>
<dd><p>Class to represent a Markov Chain with multiple kernels for factored state space,
along with methods to simulate a run.</p>
<dl class="method">
<dt id="pgmpy.models.MarkovChain.MarkovChain.add_transition_model">
<code class="descname">add_transition_model</code><span class="sig-paren">(</span><em>variable</em>, <em>transition_model</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/MarkovChain.html#MarkovChain.add_transition_model"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.MarkovChain.MarkovChain.add_transition_model" title="Permalink to this definition">¶</a></dt>
<dd><p>Adds a transition model for a particular variable.</p>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.MarkovChain.MarkovChain.add_variable">
<code class="descname">add_variable</code><span class="sig-paren">(</span><em>variable</em>, <em>card=0</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/MarkovChain.html#MarkovChain.add_variable"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.MarkovChain.MarkovChain.add_variable" title="Permalink to this definition">¶</a></dt>
<dd><p>Add a variable to the model.</p>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.MarkovChain.MarkovChain.add_variables_from">
<code class="descname">add_variables_from</code><span class="sig-paren">(</span><em>variables</em>, <em>cards</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/MarkovChain.html#MarkovChain.add_variables_from"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.MarkovChain.MarkovChain.add_variables_from" title="Permalink to this definition">¶</a></dt>
<dd><p>Add several variables to the model at once.</p>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.MarkovChain.MarkovChain.copy">
<code class="descname">copy</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/MarkovChain.html#MarkovChain.copy"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.MarkovChain.MarkovChain.copy" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns a copy of Markov Chain Model.</p>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.MarkovChain.MarkovChain.generate_sample">
<code class="descname">generate_sample</code><span class="sig-paren">(</span><em>start_state=None</em>, <em>size=1</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/MarkovChain.html#MarkovChain.generate_sample"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.MarkovChain.MarkovChain.generate_sample" title="Permalink to this definition">¶</a></dt>
<dd><p>Generator version of self.sample</p>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.MarkovChain.MarkovChain.is_stationarity">
<code class="descname">is_stationarity</code><span class="sig-paren">(</span><em>tolerance=0.2</em>, <em>sample=None</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/MarkovChain.html#MarkovChain.is_stationarity"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.MarkovChain.MarkovChain.is_stationarity" title="Permalink to this definition">¶</a></dt>
<dd><p>Checks if the given markov chain is stationary and checks the steady state
probablity values for the state are consistent.</p>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.MarkovChain.MarkovChain.prob_from_sample">
<code class="descname">prob_from_sample</code><span class="sig-paren">(</span><em>state</em>, <em>sample=None</em>, <em>window_size=None</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/MarkovChain.html#MarkovChain.prob_from_sample"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.MarkovChain.MarkovChain.prob_from_sample" title="Permalink to this definition">¶</a></dt>
<dd><p>Given an instantiation (partial or complete) of the variables of the model,
compute the probability of observing it over multiple windows in a given sample.</p>
<p>If &#8216;sample&#8217; is not passed as an argument, generate the statistic by sampling from the
Markov Chain, starting with a random initial state.</p>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.MarkovChain.MarkovChain.random_state">
<code class="descname">random_state</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/MarkovChain.html#MarkovChain.random_state"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.MarkovChain.MarkovChain.random_state" title="Permalink to this definition">¶</a></dt>
<dd><p>Generates a random state of the Markov Chain.</p>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.MarkovChain.MarkovChain.sample">
<code class="descname">sample</code><span class="sig-paren">(</span><em>start_state=None</em>, <em>size=1</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/MarkovChain.html#MarkovChain.sample"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.MarkovChain.MarkovChain.sample" title="Permalink to this definition">¶</a></dt>
<dd><p>Sample from the Markov Chain.</p>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.MarkovChain.MarkovChain.set_start_state">
<code class="descname">set_start_state</code><span class="sig-paren">(</span><em>start_state</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/MarkovChain.html#MarkovChain.set_start_state"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.MarkovChain.MarkovChain.set_start_state" title="Permalink to this definition">¶</a></dt>
<dd><p>Set the start state of the Markov Chain. If the start_state is given as a array-like iterable, its contents
are reordered in the internal representation.</p>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="module-pgmpy.models.NoisyOrModel">
<span id="noisyor-model"></span><h2>NoisyOr Model<a class="headerlink" href="#module-pgmpy.models.NoisyOrModel" title="Permalink to this headline">¶</a></h2>
<dl class="class">
<dt id="pgmpy.models.NoisyOrModel.NoisyOrModel">
<em class="property">class </em><code class="descclassname">pgmpy.models.NoisyOrModel.</code><code class="descname">NoisyOrModel</code><span class="sig-paren">(</span><em>variables</em>, <em>cardinality</em>, <em>inhibitor_probability</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/NoisyOrModel.html#NoisyOrModel"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.NoisyOrModel.NoisyOrModel" title="Permalink to this definition">¶</a></dt>
<dd><p>Base class for Noisy-Or models.</p>
<p>This is an implementation of generalized Noisy-Or models and
is not limited to Boolean variables and also any arbitrary
function can be used instead of the boolean OR function.</p>
<p>Reference: <a class="reference external" href="http://xenon.stanford.edu/~srinivas/research/6-UAI93-Srinivas-Generalization-of-Noisy-Or.pdf">http://xenon.stanford.edu/~srinivas/research/6-UAI93-Srinivas-Generalization-of-Noisy-Or.pdf</a></p>
<dl class="method">
<dt id="pgmpy.models.NoisyOrModel.NoisyOrModel.add_variables">
<code class="descname">add_variables</code><span class="sig-paren">(</span><em>variables</em>, <em>cardinality</em>, <em>inhibitor_probability</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/NoisyOrModel.html#NoisyOrModel.add_variables"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.NoisyOrModel.NoisyOrModel.add_variables" title="Permalink to this definition">¶</a></dt>
<dd><p>Adds variables to the NoisyOrModel.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>variables: list, tuple, dict (array like)</strong></p>
<blockquote>
<div><p>array containing names of the variables that are to be added.</p>
</div></blockquote>
<p><strong>cardinality: list, tuple, dict (array like)</strong></p>
<blockquote>
<div><p>array containing integers representing the cardinality
of the variables.</p>
</div></blockquote>
<p><strong>inhibitor_probability: list, tuple, dict (array_like)</strong></p>
<blockquote class="last">
<div><p>array containing the inhibitor probabilities corresponding to each variable.</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">NoisyOrModel</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">model</span> <span class="o">=</span> <span class="n">NoisyOrModel</span><span class="p">([</span><span class="s1">&#39;x1&#39;</span><span class="p">,</span> <span class="s1">&#39;x2&#39;</span><span class="p">,</span> <span class="s1">&#39;x3&#39;</span><span class="p">],</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="p">[[</span><span class="mf">0.6</span><span class="p">,</span> <span class="mf">0.4</span><span class="p">],</span>
<span class="gp">... </span>                                                     <span class="p">[</span><span class="mf">0.2</span><span class="p">,</span> <span class="mf">0.4</span><span class="p">,</span> <span class="mf">0.7</span><span class="p">],</span>
<span class="gp">... </span>                                                     <span class="p">[</span><span class="mf">0.1</span><span class="p">,</span> <span class="mf">0.</span> <span class="mi">4</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">model</span><span class="o">.</span><span class="n">add_variables</span><span class="p">([</span><span class="s1">&#39;x4&#39;</span><span class="p">],</span> <span class="p">[</span><span class="mi">3</span><span class="p">],</span> <span class="p">[</span><span class="mf">0.1</span><span class="p">,</span> <span class="mf">0.4</span><span class="p">,</span> <span class="mf">0.2</span><span class="p">])</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.NoisyOrModel.NoisyOrModel.del_variables">
<code class="descname">del_variables</code><span class="sig-paren">(</span><em>variables</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/NoisyOrModel.html#NoisyOrModel.del_variables"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.NoisyOrModel.NoisyOrModel.del_variables" title="Permalink to this definition">¶</a></dt>
<dd><p>Deletes variables from the NoisyOrModel.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>variables: list, tuple, dict (array like)</strong></p>
<blockquote class="last">
<div><p>list of variables to be deleted.</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">NoisyOrModel</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">model</span> <span class="o">=</span> <span class="n">NoisyOrModel</span><span class="p">([</span><span class="s1">&#39;x1&#39;</span><span class="p">,</span> <span class="s1">&#39;x2&#39;</span><span class="p">,</span> <span class="s1">&#39;x3&#39;</span><span class="p">],</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="p">[[</span><span class="mf">0.6</span><span class="p">,</span> <span class="mf">0.4</span><span class="p">],</span>
<span class="gp">... </span>                                                     <span class="p">[</span><span class="mf">0.2</span><span class="p">,</span> <span class="mf">0.4</span><span class="p">,</span> <span class="mf">0.7</span><span class="p">],</span>
<span class="gp">... </span>                                                     <span class="p">[</span><span class="mf">0.1</span><span class="p">,</span> <span class="mf">0.</span> <span class="mi">4</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">model</span><span class="o">.</span><span class="n">del_variables</span><span class="p">([</span><span class="s1">&#39;x1&#39;</span><span class="p">])</span>
</pre></div>
</div>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="module-pgmpy.models.NaiveBayes">
<span id="naive-bayes"></span><h2>Naive Bayes<a class="headerlink" href="#module-pgmpy.models.NaiveBayes" title="Permalink to this headline">¶</a></h2>
<dl class="class">
<dt id="pgmpy.models.NaiveBayes.NaiveBayes">
<em class="property">class </em><code class="descclassname">pgmpy.models.NaiveBayes.</code><code class="descname">NaiveBayes</code><span class="sig-paren">(</span><em>ebunch=None</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/NaiveBayes.html#NaiveBayes"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.NaiveBayes.NaiveBayes" title="Permalink to this definition">¶</a></dt>
<dd><p>Class to represent Naive Bayes.
Subclass of Bayesian Model.
Model holds directed edges from one parent node to multiple
children nodes only.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>data</strong> : input graph</p>
<blockquote class="last">
<div><p>Data to initialize graph.  If data=None (default) an empty
graph is created.  The data can be an edge list, or any
NetworkX graph object.</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<p>Create an empty Naive Bayes Model with no nodes and no edges.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">NaiveBayes</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span> <span class="o">=</span> <span class="n">NaiveBayes</span><span class="p">()</span>
</pre></div>
</div>
<p>G can be grown in several ways.</p>
<p><strong>Nodes:</strong></p>
<p>Add one node at a time:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_node</span><span class="p">(</span><span class="s1">&#39;a&#39;</span><span class="p">)</span>
</pre></div>
</div>
<p>Add the nodes from any container (a list, set or tuple or the nodes
from another graph).</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_nodes_from</span><span class="p">([</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="s1">&#39;c&#39;</span><span class="p">])</span>
</pre></div>
</div>
<p><strong>Edges:</strong></p>
<p>G can also be grown by adding edges.</p>
<p>Add one edge,</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_edge</span><span class="p">(</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">)</span>
</pre></div>
</div>
<p>a list of edges,</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_edges_from</span><span class="p">([(</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;c&#39;</span><span class="p">)])</span>
</pre></div>
</div>
<p>If some edges connect nodes not yet in the model, the nodes
are added automatically.  There are no errors when adding
nodes or edges that already exist.</p>
<p><strong>Shortcuts:</strong></p>
<p>Many common graph features allow python syntax for speed reporting.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="s1">&#39;a&#39;</span> <span class="ow">in</span> <span class="n">G</span>     <span class="c1"># check if node in graph</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">len</span><span class="p">(</span><span class="n">G</span><span class="p">)</span>  <span class="c1"># number of nodes in graph</span>
<span class="go">3</span>
</pre></div>
</div>
<dl class="method">
<dt id="pgmpy.models.NaiveBayes.NaiveBayes.active_trail_nodes">
<code class="descname">active_trail_nodes</code><span class="sig-paren">(</span><em>start</em>, <em>observed=None</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/NaiveBayes.html#NaiveBayes.active_trail_nodes"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.NaiveBayes.NaiveBayes.active_trail_nodes" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns all the nodes reachable from start via an active trail.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>start: Graph node</strong></p>
<p><strong>observed</strong> : List of nodes (optional)</p>
<blockquote class="last">
<div><p>If given the active trail would be computed assuming these nodes to be observed.</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">NaiveBayes</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">model</span> <span class="o">=</span> <span class="n">NaiveBayes</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">model</span><span class="o">.</span><span class="n">add_nodes_from</span><span class="p">([</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="s1">&#39;c&#39;</span><span class="p">,</span> <span class="s1">&#39;d&#39;</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">model</span><span class="o">.</span><span class="n">add_edges_from</span><span class="p">([(</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;c&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;d&#39;</span><span class="p">)])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">model</span><span class="o">.</span><span class="n">active_trail_nodes</span><span class="p">(</span><span class="s1">&#39;a&#39;</span><span class="p">)</span>
<span class="go">{&#39;a&#39;, &#39;b&#39;, &#39;c&#39;, &#39;d&#39;}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">model</span><span class="o">.</span><span class="n">active_trail_nodes</span><span class="p">(</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="p">[</span><span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="s1">&#39;c&#39;</span><span class="p">])</span>
<span class="go">{&#39;a&#39;, &#39;d&#39;}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">model</span><span class="o">.</span><span class="n">active_trail_nodes</span><span class="p">(</span><span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="p">[</span><span class="s1">&#39;a&#39;</span><span class="p">])</span>
<span class="go">{&#39;b&#39;}</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.NaiveBayes.NaiveBayes.add_edge">
<code class="descname">add_edge</code><span class="sig-paren">(</span><em>u</em>, <em>v</em>, <em>*kwargs</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/NaiveBayes.html#NaiveBayes.add_edge"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.NaiveBayes.NaiveBayes.add_edge" title="Permalink to this definition">¶</a></dt>
<dd><p>Add an edge between u and v.</p>
<p>The nodes u and v will be automatically added if they are
not already in the graph</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>u,v</strong> : nodes</p>
<blockquote class="last">
<div><p>Nodes can be any hashable python object.</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">NaiveBayes</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span> <span class="o">=</span> <span class="n">NaiveBayes</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_nodes_from</span><span class="p">([</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="s1">&#39;c&#39;</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_edge</span><span class="p">(</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_edge</span><span class="p">(</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;c&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">edges</span><span class="p">()</span>
<span class="go">[(&#39;a&#39;, &#39;c&#39;), (&#39;a&#39;, &#39;b&#39;)]</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.NaiveBayes.NaiveBayes.fit">
<code class="descname">fit</code><span class="sig-paren">(</span><em>data</em>, <em>parent_node=None</em>, <em>estimator=None</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/NaiveBayes.html#NaiveBayes.fit"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.NaiveBayes.NaiveBayes.fit" title="Permalink to this definition">¶</a></dt>
<dd><p>Computes the CPD for each node from a given data in the form of a pandas dataframe.
If a variable from the data is not present in the model, it adds that node into the model.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>data</strong> : pandas DataFrame object</p>
<blockquote>
<div><p>A DataFrame object with column names same as the variable names of network</p>
</div></blockquote>
<p><strong>parent_node: any hashable python object (optional)</strong></p>
<blockquote>
<div><p>Parent node of the model, if not specified it looks for a previously specified
parent node.</p>
</div></blockquote>
<p><strong>estimator: Estimator class</strong></p>
<blockquote class="last">
<div><p>Any pgmpy estimator. If nothing is specified, the default <code class="docutils literal"><span class="pre">MaximumLikelihoodEstimator</span></code>
would be used.</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">pandas</span> <span class="k">as</span> <span class="nn">pd</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">NaiveBayes</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">model</span> <span class="o">=</span> <span class="n">NaiveBayes</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">values</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">randint</span><span class="p">(</span><span class="n">low</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">high</span><span class="o">=</span><span class="mi">2</span><span class="p">,</span> <span class="n">size</span><span class="o">=</span><span class="p">(</span><span class="mi">1000</span><span class="p">,</span> <span class="mi">5</span><span class="p">)),</span>
<span class="gp">... </span>                      <span class="n">columns</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;A&#39;</span><span class="p">,</span> <span class="s1">&#39;B&#39;</span><span class="p">,</span> <span class="s1">&#39;C&#39;</span><span class="p">,</span> <span class="s1">&#39;D&#39;</span><span class="p">,</span> <span class="s1">&#39;E&#39;</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">model</span><span class="o">.</span><span class="n">fit</span><span class="p">(</span><span class="n">values</span><span class="p">,</span> <span class="s1">&#39;A&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">model</span><span class="o">.</span><span class="n">get_cpds</span><span class="p">()</span>
<span class="go">[&lt;TabularCPD representing P(D:2 | A:2) at 0x4b72870&gt;,</span>
<span class="go"> &lt;TabularCPD representing P(E:2 | A:2) at 0x4bb2150&gt;,</span>
<span class="go"> &lt;TabularCPD representing P(A:2) at 0x4bb23d0&gt;,</span>
<span class="go"> &lt;TabularCPD representing P(B:2 | A:2) at 0x4bb24b0&gt;,</span>
<span class="go"> &lt;TabularCPD representing P(C:2 | A:2) at 0x4bb2750&gt;]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">model</span><span class="o">.</span><span class="n">edges</span><span class="p">()</span>
<span class="go">[(&#39;A&#39;, &#39;D&#39;), (&#39;A&#39;, &#39;E&#39;), (&#39;A&#39;, &#39;B&#39;), (&#39;A&#39;, &#39;C&#39;)]</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.NaiveBayes.NaiveBayes.local_independencies">
<code class="descname">local_independencies</code><span class="sig-paren">(</span><em>variables</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/NaiveBayes.html#NaiveBayes.local_independencies"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.NaiveBayes.NaiveBayes.local_independencies" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns an instance of Independencies containing the local independencies
of each of the variables.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>variables: str or array like</strong></p>
<blockquote class="last">
<div><p>variables whose local independencies are to found.</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">NaiveBayes</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">model</span> <span class="o">=</span> <span class="n">NaiveBayes</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">model</span><span class="o">.</span><span class="n">add_edges_from</span><span class="p">([(</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;c&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;d&#39;</span><span class="p">)])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ind</span> <span class="o">=</span> <span class="n">model</span><span class="o">.</span><span class="n">local_independencies</span><span class="p">(</span><span class="s1">&#39;b&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ind</span>
<span class="go">(b _|_ d, c | a)</span>
</pre></div>
</div>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="module-pgmpy.models.DynamicBayesianNetwork">
<span id="dynamicbayesiannetwork"></span><h2>DynamicBayesianNetwork<a class="headerlink" href="#module-pgmpy.models.DynamicBayesianNetwork" title="Permalink to this headline">¶</a></h2>
<dl class="class">
<dt id="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork">
<em class="property">class </em><code class="descclassname">pgmpy.models.DynamicBayesianNetwork.</code><code class="descname">DynamicBayesianNetwork</code><span class="sig-paren">(</span><em>ebunch=None</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/DynamicBayesianNetwork.html#DynamicBayesianNetwork"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <code class="xref py py-class docutils literal"><span class="pre">pgmpy.base.DirectedGraph.DirectedGraph</span></code></p>
<dl class="method">
<dt id="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.add_cpds">
<code class="descname">add_cpds</code><span class="sig-paren">(</span><em>*cpds</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/DynamicBayesianNetwork.html#DynamicBayesianNetwork.add_cpds"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.add_cpds" title="Permalink to this definition">¶</a></dt>
<dd><p>This method adds the cpds to the dynamic bayesian network.
Note that while adding variables and the evidence in cpd,
they have to be of the following form
(node_name, time_slice)
Here, node_name is the node that is inserted
while the time_slice is an integer value, which denotes
the index of the time_slice that the node belongs to.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>cpds</strong> : list, set, tuple (array-like)</p>
<blockquote class="last">
<div><p>List of CPDs which are to be associated with the model. Each CPD
should be an instance of <cite>TabularCPD</cite>.</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">DynamicBayesianNetwork</span> <span class="k">as</span> <span class="n">DBN</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.factors.discrete</span> <span class="k">import</span> <span class="n">TabularCPD</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dbn</span> <span class="o">=</span> <span class="n">DBN</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dbn</span><span class="o">.</span><span class="n">add_edges_from</span><span class="p">([((</span><span class="s1">&#39;D&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">),(</span><span class="s1">&#39;G&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">)),((</span><span class="s1">&#39;I&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">),(</span><span class="s1">&#39;G&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">)),((</span><span class="s1">&#39;D&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">),(</span><span class="s1">&#39;D&#39;</span><span class="p">,</span> <span class="mi">1</span><span class="p">)),((</span><span class="s1">&#39;I&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">),(</span><span class="s1">&#39;I&#39;</span><span class="p">,</span> <span class="mi">1</span><span class="p">))])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">grade_cpd</span> <span class="o">=</span> <span class="n">TabularCPD</span><span class="p">((</span><span class="s1">&#39;G&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span> <span class="mi">3</span><span class="p">,</span> <span class="p">[[</span><span class="mf">0.3</span><span class="p">,</span> <span class="mf">0.05</span><span class="p">,</span> <span class="mf">0.9</span><span class="p">,</span> <span class="mf">0.5</span><span class="p">],</span>
<span class="gp">... </span>                                     <span class="p">[</span><span class="mf">0.4</span><span class="p">,</span> <span class="mf">0.25</span><span class="p">,</span> <span class="mf">0.8</span><span class="p">,</span> <span class="mf">0.03</span><span class="p">],</span>
<span class="gp">... </span>                                     <span class="p">[</span><span class="mf">0.3</span><span class="p">,</span> <span class="mf">0.7</span><span class="p">,</span> <span class="mf">0.02</span><span class="p">,</span> <span class="mf">0.2</span><span class="p">]],</span>
<span class="gp">... </span>                       <span class="n">evidence</span><span class="o">=</span><span class="p">[(</span><span class="s1">&#39;I&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">),(</span><span class="s1">&#39;D&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">)],</span>
<span class="gp">... </span>                       <span class="n">evidence_card</span><span class="o">=</span><span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">d_i_cpd</span> <span class="o">=</span> <span class="n">TabularCPD</span><span class="p">((</span><span class="s1">&#39;D&#39;</span><span class="p">,</span><span class="mi">1</span><span class="p">),</span> <span class="mi">2</span><span class="p">,</span> <span class="p">[[</span><span class="mf">0.6</span><span class="p">,</span> <span class="mf">0.3</span><span class="p">],</span>
<span class="gp">... </span>                                  <span class="p">[</span><span class="mf">0.4</span><span class="p">,</span> <span class="mf">0.7</span><span class="p">]],</span>
<span class="gp">... </span>                     <span class="n">evidence</span><span class="o">=</span><span class="p">[(</span><span class="s1">&#39;D&#39;</span><span class="p">,</span><span class="mi">0</span><span class="p">)],</span>
<span class="gp">... </span>                     <span class="n">evidence_card</span><span class="o">=</span><span class="mi">2</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">diff_cpd</span> <span class="o">=</span> <span class="n">TabularCPD</span><span class="p">((</span><span class="s1">&#39;D&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span> <span class="mi">2</span><span class="p">,</span> <span class="p">[[</span><span class="mf">0.6</span><span class="p">,</span> <span class="mf">0.4</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">intel_cpd</span> <span class="o">=</span> <span class="n">TabularCPD</span><span class="p">((</span><span class="s1">&#39;I&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span> <span class="mi">2</span><span class="p">,</span> <span class="p">[[</span><span class="mf">0.7</span><span class="p">,</span> <span class="mf">0.3</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">i_i_cpd</span> <span class="o">=</span> <span class="n">TabularCPD</span><span class="p">((</span><span class="s1">&#39;I&#39;</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span> <span class="mi">2</span><span class="p">,</span> <span class="p">[[</span><span class="mf">0.5</span><span class="p">,</span> <span class="mf">0.4</span><span class="p">],</span>
<span class="gp">... </span>                                   <span class="p">[</span><span class="mf">0.5</span><span class="p">,</span> <span class="mf">0.6</span><span class="p">]],</span>
<span class="gp">... </span>                     <span class="n">evidence</span><span class="o">=</span><span class="p">[(</span><span class="s1">&#39;I&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">)],</span>
<span class="gp">... </span>                     <span class="n">evidence_card</span><span class="o">=</span><span class="mi">2</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dbn</span><span class="o">.</span><span class="n">add_cpds</span><span class="p">(</span><span class="n">grade_cpd</span><span class="p">,</span> <span class="n">d_i_cpd</span><span class="p">,</span> <span class="n">diff_cpd</span><span class="p">,</span> <span class="n">intel_cpd</span><span class="p">,</span> <span class="n">i_i_cpd</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dbn</span><span class="o">.</span><span class="n">get_cpds</span><span class="p">()</span>
<span class="go">[&lt;TabularCPD representing P((&#39;G&#39;, 0):3 | (&#39;I&#39;, 0):2, (&#39;D&#39;, 0):2) at 0x7ff7f27b0cf8&gt;,</span>
<span class="go"> &lt;TabularCPD representing P((&#39;D&#39;, 1):2 | (&#39;D&#39;, 0):2) at 0x7ff810b9c2e8&gt;,</span>
<span class="go"> &lt;TabularCPD representing P((&#39;D&#39;, 0):2) at 0x7ff7f27e6f98&gt;,</span>
<span class="go"> &lt;TabularCPD representing P((&#39;I&#39;, 0):2) at 0x7ff7f27e6ba8&gt;,</span>
<span class="go"> &lt;TabularCPD representing P((&#39;I&#39;, 1):2 | (&#39;I&#39;, 0):2) at 0x7ff7f27e6668&gt;]</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.add_cycle">
<code class="descname">add_cycle</code><span class="sig-paren">(</span><em>nodes</em>, <em>**attr</em><span class="sig-paren">)</span><a class="headerlink" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.add_cycle" title="Permalink to this definition">¶</a></dt>
<dd><p>Add a cycle.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>nodes: iterable container</strong></p>
<blockquote>
<div><p>A container of nodes.  A cycle will be constructed from
the nodes (in order) and added to the graph.</p>
</div></blockquote>
<p><strong>attr</strong> : keyword arguments, optional (default= no attributes)</p>
<blockquote class="last">
<div><p>Attributes to add to every edge in cycle.</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.add_path" title="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.add_path"><code class="xref py py-obj docutils literal"><span class="pre">add_path</span></code></a>, <a class="reference internal" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.add_star" title="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.add_star"><code class="xref py py-obj docutils literal"><span class="pre">add_star</span></code></a></p>
</div>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">=</span><span class="n">nx</span><span class="o">.</span><span class="n">Graph</span><span class="p">()</span>   <span class="c1"># or DiGraph, MultiGraph, MultiDiGraph, etc</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_cycle</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_cycle</span><span class="p">([</span><span class="mi">10</span><span class="p">,</span><span class="mi">11</span><span class="p">,</span><span class="mi">12</span><span class="p">],</span><span class="n">weight</span><span class="o">=</span><span class="mi">7</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.add_edge">
<code class="descname">add_edge</code><span class="sig-paren">(</span><em>start</em>, <em>end</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/DynamicBayesianNetwork.html#DynamicBayesianNetwork.add_edge"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.add_edge" title="Permalink to this definition">¶</a></dt>
<dd><p>Add an edge between two nodes.</p>
<p>The nodes will be automatically added if they are not present in the network.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>start: tuple</strong></p>
<blockquote>
<div><p>Both the start and end nodes should specify the time slice as
(node_name, time_slice). Here, node_name can be any hashable
python object while the time_slice is an integer value,
which denotes the time slice that the node belongs to.</p>
</div></blockquote>
<p><strong>end: tuple</strong></p>
<blockquote class="last">
<div><p>Both the start and end nodes should specify the time slice as
(node_name, time_slice). Here, node_name can be any hashable
python object while the time_slice is an integer value,
which denotes the time slice that the node belongs to.</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">DynamicBayesianNetwork</span> <span class="k">as</span> <span class="n">DBN</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">model</span> <span class="o">=</span> <span class="n">DBN</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">model</span><span class="o">.</span><span class="n">add_nodes_from</span><span class="p">([</span><span class="s1">&#39;D&#39;</span><span class="p">,</span> <span class="s1">&#39;I&#39;</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">model</span><span class="o">.</span><span class="n">add_edge</span><span class="p">((</span><span class="s1">&#39;D&#39;</span><span class="p">,</span><span class="mi">0</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;I&#39;</span><span class="p">,</span><span class="mi">0</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">model</span><span class="o">.</span><span class="n">edges</span><span class="p">()</span>
<span class="go">[((&#39;D&#39;, 1), (&#39;I&#39;, 1)), ((&#39;D&#39;, 0), (&#39;I&#39;, 0))]</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.add_edges_from">
<code class="descname">add_edges_from</code><span class="sig-paren">(</span><em>ebunch</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/DynamicBayesianNetwork.html#DynamicBayesianNetwork.add_edges_from"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.add_edges_from" title="Permalink to this definition">¶</a></dt>
<dd><p>Add all the edges in ebunch.</p>
<p>If nodes referred in the ebunch are not already present, they
will be automatically added. Node names can be any hashable python object.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>ebunch</strong> : list, array-like</p>
<blockquote class="last">
<div><p>List of edges to add. Each edge must be of the form of
((start, time_slice), (end, time_slice)).</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">DynamicBayesianNetwork</span> <span class="k">as</span> <span class="n">DBN</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dbn</span> <span class="o">=</span> <span class="n">DBN</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dbn</span><span class="o">.</span><span class="n">add_edges_from</span><span class="p">([((</span><span class="s1">&#39;D&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;G&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">)),</span> <span class="p">((</span><span class="s1">&#39;I&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;G&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">))])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dbn</span><span class="o">.</span><span class="n">nodes</span><span class="p">()</span>
<span class="go">[&#39;G&#39;, &#39;I&#39;, &#39;D&#39;]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dbn</span><span class="o">.</span><span class="n">edges</span><span class="p">()</span>
<span class="go">[((&#39;D&#39;, 1), (&#39;G&#39;, 1)),</span>
<span class="go"> ((&#39;I&#39;, 1), (&#39;G&#39;, 1)),</span>
<span class="go"> ((&#39;D&#39;, 0), (&#39;G&#39;, 0)),</span>
<span class="go"> ((&#39;I&#39;, 0), (&#39;G&#39;, 0))]</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.add_node">
<code class="descname">add_node</code><span class="sig-paren">(</span><em>node</em>, <em>**attr</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/DynamicBayesianNetwork.html#DynamicBayesianNetwork.add_node"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.add_node" title="Permalink to this definition">¶</a></dt>
<dd><p>Adds a single node to the Network</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>node: node</strong></p>
<blockquote class="last">
<div><p>A node can be any hashable Python object.</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">DynamicBayesianNetwork</span> <span class="k">as</span> <span class="n">DBN</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dbn</span> <span class="o">=</span> <span class="n">DBN</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dbn</span><span class="o">.</span><span class="n">add_node</span><span class="p">(</span><span class="s1">&#39;A&#39;</span><span class="p">)</span>
<span class="go">[&#39;A&#39;]</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.add_nodes_from">
<code class="descname">add_nodes_from</code><span class="sig-paren">(</span><em>nodes</em>, <em>**attr</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/DynamicBayesianNetwork.html#DynamicBayesianNetwork.add_nodes_from"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.add_nodes_from" title="Permalink to this definition">¶</a></dt>
<dd><p>Add multiple nodes to the Network.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>nodes: iterable container</strong></p>
<blockquote class="last">
<div><p>A container of nodes (list, dict, set, etc.).</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">DynamicBayesianNetwork</span> <span class="k">as</span> <span class="n">DBN</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dbn</span> <span class="o">=</span> <span class="n">DBN</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dbn</span><span class="o">.</span><span class="n">add_nodes_from</span><span class="p">([</span><span class="s1">&#39;A&#39;</span><span class="p">,</span> <span class="s1">&#39;B&#39;</span><span class="p">,</span> <span class="s1">&#39;C&#39;</span><span class="p">])</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.add_path">
<code class="descname">add_path</code><span class="sig-paren">(</span><em>nodes</em>, <em>**attr</em><span class="sig-paren">)</span><a class="headerlink" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.add_path" title="Permalink to this definition">¶</a></dt>
<dd><p>Add a path.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>nodes</strong> : iterable container</p>
<blockquote>
<div><p>A container of nodes.  A path will be constructed from
the nodes (in order) and added to the graph.</p>
</div></blockquote>
<p><strong>attr</strong> : keyword arguments, optional (default= no attributes)</p>
<blockquote class="last">
<div><p>Attributes to add to every edge in path.</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.add_star" title="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.add_star"><code class="xref py py-obj docutils literal"><span class="pre">add_star</span></code></a>, <a class="reference internal" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.add_cycle" title="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.add_cycle"><code class="xref py py-obj docutils literal"><span class="pre">add_cycle</span></code></a></p>
</div>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">=</span><span class="n">nx</span><span class="o">.</span><span class="n">Graph</span><span class="p">()</span>   <span class="c1"># or DiGraph, MultiGraph, MultiDiGraph, etc</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_path</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_path</span><span class="p">([</span><span class="mi">10</span><span class="p">,</span><span class="mi">11</span><span class="p">,</span><span class="mi">12</span><span class="p">],</span><span class="n">weight</span><span class="o">=</span><span class="mi">7</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.add_star">
<code class="descname">add_star</code><span class="sig-paren">(</span><em>nodes</em>, <em>**attr</em><span class="sig-paren">)</span><a class="headerlink" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.add_star" title="Permalink to this definition">¶</a></dt>
<dd><p>Add a star.</p>
<p>The first node in nodes is the middle of the star.  It is connected
to all other nodes.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>nodes</strong> : iterable container</p>
<blockquote>
<div><p>A container of nodes.</p>
</div></blockquote>
<p><strong>attr</strong> : keyword arguments, optional (default= no attributes)</p>
<blockquote class="last">
<div><p>Attributes to add to every edge in star.</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.add_path" title="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.add_path"><code class="xref py py-obj docutils literal"><span class="pre">add_path</span></code></a>, <a class="reference internal" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.add_cycle" title="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.add_cycle"><code class="xref py py-obj docutils literal"><span class="pre">add_cycle</span></code></a></p>
</div>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">G</span> <span class="o">=</span> <span class="n">nx</span><span class="o">.</span><span class="n">Graph</span><span class="p">()</span>   <span class="c1"># or DiGraph, MultiGraph, MultiDiGraph, etc</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_star</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_star</span><span class="p">([</span><span class="mi">10</span><span class="p">,</span><span class="mi">11</span><span class="p">,</span><span class="mi">12</span><span class="p">],</span><span class="n">weight</span><span class="o">=</span><span class="mi">2</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.add_weighted_edges_from">
<code class="descname">add_weighted_edges_from</code><span class="sig-paren">(</span><em>ebunch</em>, <em>weight='weight'</em>, <em>**attr</em><span class="sig-paren">)</span><a class="headerlink" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.add_weighted_edges_from" title="Permalink to this definition">¶</a></dt>
<dd><p>Add all the edges in ebunch as weighted edges with specified
weights.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>ebunch</strong> : container of edges</p>
<blockquote>
<div><p>Each edge given in the list or container will be added
to the graph. The edges must be given as 3-tuples (u,v,w)
where w is a number.</p>
</div></blockquote>
<p><strong>weight</strong> : string, optional (default= &#8216;weight&#8217;)</p>
<blockquote>
<div><p>The attribute name for the edge weights to be added.</p>
</div></blockquote>
<p><strong>attr</strong> : keyword arguments, optional (default= no attributes)</p>
<blockquote class="last">
<div><p>Edge attributes to add/update for all edges.</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<dl class="last docutils">
<dt><a class="reference internal" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.add_edge" title="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.add_edge"><code class="xref py py-obj docutils literal"><span class="pre">add_edge</span></code></a></dt>
<dd>add a single edge</dd>
<dt><a class="reference internal" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.add_edges_from" title="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.add_edges_from"><code class="xref py py-obj docutils literal"><span class="pre">add_edges_from</span></code></a></dt>
<dd>add multiple edges</dd>
</dl>
</div>
<p class="rubric">Notes</p>
<p>Adding the same edge twice for Graph/DiGraph simply updates
the edge data.  For MultiGraph/MultiDiGraph, duplicate edges
are stored.</p>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">G</span> <span class="o">=</span> <span class="n">nx</span><span class="o">.</span><span class="n">Graph</span><span class="p">()</span>   <span class="c1"># or DiGraph, MultiGraph, MultiDiGraph, etc</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_weighted_edges_from</span><span class="p">([(</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mf">3.0</span><span class="p">),(</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mf">7.5</span><span class="p">)])</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.adjacency_iter">
<code class="descname">adjacency_iter</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.adjacency_iter" title="Permalink to this definition">¶</a></dt>
<dd><p>Return an iterator of (node, adjacency dict) tuples for all nodes.</p>
<p>This is the fastest way to look at every edge.
For directed graphs, only outgoing adjacencies are included.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><strong>adj_iter</strong> : iterator</p>
<blockquote class="last">
<div><p>An iterator of (node, adjacency dictionary) for all nodes in
the graph.</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.adjacency_list" title="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.adjacency_list"><code class="xref py py-obj docutils literal"><span class="pre">adjacency_list</span></code></a></p>
</div>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">G</span> <span class="o">=</span> <span class="n">nx</span><span class="o">.</span><span class="n">Graph</span><span class="p">()</span>   <span class="c1"># or DiGraph, MultiGraph, MultiDiGraph, etc</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_path</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">[(</span><span class="n">n</span><span class="p">,</span><span class="n">nbrdict</span><span class="p">)</span> <span class="k">for</span> <span class="n">n</span><span class="p">,</span><span class="n">nbrdict</span> <span class="ow">in</span> <span class="n">G</span><span class="o">.</span><span class="n">adjacency_iter</span><span class="p">()]</span>
<span class="go">[(0, {1: {}}), (1, {0: {}, 2: {}}), (2, {1: {}, 3: {}}), (3, {2: {}})]</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.adjacency_list">
<code class="descname">adjacency_list</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.adjacency_list" title="Permalink to this definition">¶</a></dt>
<dd><p>Return an adjacency list representation of the graph.</p>
<p>The output adjacency list is in the order of G.nodes().
For directed graphs, only outgoing adjacencies are included.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><strong>adj_list</strong> : lists of lists</p>
<blockquote class="last">
<div><p>The adjacency structure of the graph as a list of lists.</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.adjacency_iter" title="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.adjacency_iter"><code class="xref py py-obj docutils literal"><span class="pre">adjacency_iter</span></code></a></p>
</div>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">G</span> <span class="o">=</span> <span class="n">nx</span><span class="o">.</span><span class="n">Graph</span><span class="p">()</span>   <span class="c1"># or DiGraph, MultiGraph, MultiDiGraph, etc</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_path</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">adjacency_list</span><span class="p">()</span> <span class="c1"># in order given by G.nodes()</span>
<span class="go">[[1], [0, 2], [1, 3], [2]]</span>
</pre></div>
</div>
</dd></dl>

<dl class="attribute">
<dt id="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.adjlist_dict_factory">
<code class="descname">adjlist_dict_factory</code><a class="headerlink" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.adjlist_dict_factory" title="Permalink to this definition">¶</a></dt>
<dd><p>alias of <a class="reference external" href="https://docs.python.org/2/library/stdtypes.html#dict" title="(in Python v2.7)"><code class="xref py py-class docutils literal"><span class="pre">dict</span></code></a></p>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.check_model">
<code class="descname">check_model</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/DynamicBayesianNetwork.html#DynamicBayesianNetwork.check_model"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.check_model" title="Permalink to this definition">¶</a></dt>
<dd><p>Check the model for various errors. This method checks for the following
errors.</p>
<ul class="simple">
<li><dl class="first docutils">
<dt>Checks if the sum of the probabilities in each associated CPD for each</dt>
<dd>state is equal to 1 (tol=0.01).</dd>
</dl>
</li>
<li>Checks if the CPDs associated with nodes are consistent with their parents.</li>
</ul>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">boolean: True if everything seems to be order. Otherwise raises error</p>
<blockquote class="last">
<div><p>according to the problem.</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.clear">
<code class="descname">clear</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.clear" title="Permalink to this definition">¶</a></dt>
<dd><p>Remove all nodes and edges from the graph.</p>
<p>This also removes the name, and all graph, node, and edge attributes.</p>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">G</span> <span class="o">=</span> <span class="n">nx</span><span class="o">.</span><span class="n">Graph</span><span class="p">()</span>   <span class="c1"># or DiGraph, MultiGraph, MultiDiGraph, etc</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_path</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">clear</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">nodes</span><span class="p">()</span>
<span class="go">[]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">edges</span><span class="p">()</span>
<span class="go">[]</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.copy">
<code class="descname">copy</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/DynamicBayesianNetwork.html#DynamicBayesianNetwork.copy"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.copy" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns a copy of the dynamic bayesian network.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">DynamicBayesianNetwork: copy of the dynamic bayesian network</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">DynamicBayesianNetwork</span> <span class="k">as</span> <span class="n">DBN</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.factors.discrete</span> <span class="k">import</span> <span class="n">TabularCPD</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dbn</span> <span class="o">=</span> <span class="n">DBN</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dbn</span><span class="o">.</span><span class="n">add_edges_from</span><span class="p">([((</span><span class="s1">&#39;D&#39;</span><span class="p">,</span><span class="mi">0</span><span class="p">),(</span><span class="s1">&#39;G&#39;</span><span class="p">,</span><span class="mi">0</span><span class="p">)),((</span><span class="s1">&#39;I&#39;</span><span class="p">,</span><span class="mi">0</span><span class="p">),(</span><span class="s1">&#39;G&#39;</span><span class="p">,</span><span class="mi">0</span><span class="p">)),((</span><span class="s1">&#39;D&#39;</span><span class="p">,</span><span class="mi">0</span><span class="p">),(</span><span class="s1">&#39;D&#39;</span><span class="p">,</span><span class="mi">1</span><span class="p">)),((</span><span class="s1">&#39;I&#39;</span><span class="p">,</span><span class="mi">0</span><span class="p">),(</span><span class="s1">&#39;I&#39;</span><span class="p">,</span><span class="mi">1</span><span class="p">))])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">grade_cpd</span> <span class="o">=</span>  <span class="n">TabularCPD</span><span class="p">((</span><span class="s1">&#39;G&#39;</span><span class="p">,</span><span class="mi">0</span><span class="p">),</span> <span class="mi">3</span><span class="p">,</span> <span class="p">[[</span><span class="mf">0.3</span><span class="p">,</span><span class="mf">0.05</span><span class="p">,</span><span class="mf">0.9</span><span class="p">,</span><span class="mf">0.5</span><span class="p">],</span>
<span class="go">                                [0.4,0.25,0.8,0.03],</span>
<span class="go">                                [0.3,0.7,0.02,0.2]], [(&#39;I&#39;, 0),(&#39;D&#39;, 0)],[2,2])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dbn</span><span class="o">.</span><span class="n">add_cpds</span><span class="p">(</span><span class="n">grade_cpd</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dbn_copy</span> <span class="o">=</span> <span class="n">dbn</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dbn_copy</span><span class="o">.</span><span class="n">nodes</span><span class="p">()</span>
<span class="go">[&#39;Z&#39;, &#39;G&#39;, &#39;I&#39;, &#39;D&#39;]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dbn_copy</span><span class="o">.</span><span class="n">edges</span><span class="p">()</span>
<span class="go">[((&#39;I&#39;, 1), (&#39;G&#39;, 1)),</span>
<span class="go">((&#39;I&#39;, 0), (&#39;I&#39;, 1)),</span>
<span class="go">((&#39;I&#39;, 0), (&#39;G&#39;, 0)),</span>
<span class="go">((&#39;D&#39;, 1), (&#39;G&#39;, 1)),</span>
<span class="go">((&#39;D&#39;, 0), (&#39;G&#39;, 0)),</span>
<span class="go">((&#39;D&#39;, 0), (&#39;D&#39;, 1))]</span>
<span class="go">&gt;&gt; dbn_copy.get_cpds()</span>
<span class="go">[&lt;TabularCPD representing P((&#39;G&#39;, 0):3 | (&#39;I&#39;, 0):2, (&#39;D&#39;, 0):2) at 0x7f13961a3320&gt;]</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.degree">
<code class="descname">degree</code><span class="sig-paren">(</span><em>nbunch=None</em>, <em>weight=None</em><span class="sig-paren">)</span><a class="headerlink" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.degree" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the degree of a node or nodes.</p>
<p>The node degree is the number of edges adjacent to that node.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>nbunch</strong> : iterable container, optional (default=all nodes)</p>
<blockquote>
<div><p>A container of nodes.  The container will be iterated
through once.</p>
</div></blockquote>
<p><strong>weight</strong> : string or None, optional (default=None)</p>
<blockquote>
<div><p>The edge attribute that holds the numerical value used
as a weight.  If None, then each edge has weight 1.
The degree is the sum of the edge weights adjacent to the node.</p>
</div></blockquote>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><strong>nd</strong> : dictionary, or number</p>
<blockquote class="last">
<div><p>A dictionary with nodes as keys and degree as values or
a number if a single node is specified.</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">G</span> <span class="o">=</span> <span class="n">nx</span><span class="o">.</span><span class="n">Graph</span><span class="p">()</span>   <span class="c1"># or DiGraph, MultiGraph, MultiDiGraph, etc</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_path</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">degree</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
<span class="go">1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">degree</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">])</span>
<span class="go">{0: 1, 1: 2}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">list</span><span class="p">(</span><span class="n">G</span><span class="o">.</span><span class="n">degree</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">])</span><span class="o">.</span><span class="n">values</span><span class="p">())</span>
<span class="go">[1, 2]</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.degree_iter">
<code class="descname">degree_iter</code><span class="sig-paren">(</span><em>nbunch=None</em>, <em>weight=None</em><span class="sig-paren">)</span><a class="headerlink" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.degree_iter" title="Permalink to this definition">¶</a></dt>
<dd><p>Return an iterator for (node, degree).</p>
<p>The node degree is the number of edges adjacent to the node.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>nbunch</strong> : iterable container, optional (default=all nodes)</p>
<blockquote>
<div><p>A container of nodes.  The container will be iterated
through once.</p>
</div></blockquote>
<p><strong>weight</strong> : string or None, optional (default=None)</p>
<blockquote>
<div><p>The edge attribute that holds the numerical value used
as a weight.  If None, then each edge has weight 1.
The degree is the sum of the edge weights adjacent to the node.</p>
</div></blockquote>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><strong>nd_iter</strong> : an iterator</p>
<blockquote class="last">
<div><p>The iterator returns two-tuples of (node, degree).</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.degree" title="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.degree"><code class="xref py py-obj docutils literal"><span class="pre">degree</span></code></a>, <a class="reference internal" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.in_degree" title="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.in_degree"><code class="xref py py-obj docutils literal"><span class="pre">in_degree</span></code></a>, <a class="reference internal" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.out_degree" title="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.out_degree"><code class="xref py py-obj docutils literal"><span class="pre">out_degree</span></code></a>, <a class="reference internal" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.in_degree_iter" title="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.in_degree_iter"><code class="xref py py-obj docutils literal"><span class="pre">in_degree_iter</span></code></a>, <a class="reference internal" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.out_degree_iter" title="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.out_degree_iter"><code class="xref py py-obj docutils literal"><span class="pre">out_degree_iter</span></code></a></p>
</div>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">G</span> <span class="o">=</span> <span class="n">nx</span><span class="o">.</span><span class="n">DiGraph</span><span class="p">()</span>   <span class="c1"># or MultiDiGraph</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_path</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">list</span><span class="p">(</span><span class="n">G</span><span class="o">.</span><span class="n">degree_iter</span><span class="p">(</span><span class="mi">0</span><span class="p">))</span> <span class="c1"># node 0 with degree 1</span>
<span class="go">[(0, 1)]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">list</span><span class="p">(</span><span class="n">G</span><span class="o">.</span><span class="n">degree_iter</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">]))</span>
<span class="go">[(0, 1), (1, 2)]</span>
</pre></div>
</div>
</dd></dl>

<dl class="attribute">
<dt id="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.edge_attr_dict_factory">
<code class="descname">edge_attr_dict_factory</code><a class="headerlink" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.edge_attr_dict_factory" title="Permalink to this definition">¶</a></dt>
<dd><p>alias of <a class="reference external" href="https://docs.python.org/2/library/stdtypes.html#dict" title="(in Python v2.7)"><code class="xref py py-class docutils literal"><span class="pre">dict</span></code></a></p>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.edges">
<code class="descname">edges</code><span class="sig-paren">(</span><em>nbunch=None</em>, <em>data=False</em>, <em>default=None</em><span class="sig-paren">)</span><a class="headerlink" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.edges" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a list of edges.</p>
<p>Edges are returned as tuples with optional data
in the order (node, neighbor, data).</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>nbunch</strong> : iterable container, optional (default= all nodes)</p>
<blockquote>
<div><p>A container of nodes.  The container will be iterated
through once.</p>
</div></blockquote>
<p><strong>data</strong> : string or bool, optional (default=False)</p>
<blockquote>
<div><p>The edge attribute returned in 3-tuple (u,v,ddict[data]).
If True, return edge attribute dict in 3-tuple (u,v,ddict).
If False, return 2-tuple (u,v).</p>
</div></blockquote>
<p><strong>default</strong> : value, optional (default=None)</p>
<blockquote>
<div><p>Value used for edges that dont have the requested attribute.
Only relevant if data is not True or False.</p>
</div></blockquote>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">edge_list: list of edge tuples</p>
<blockquote class="last">
<div><p>Edges that are adjacent to any node in nbunch, or a list
of all edges if nbunch is not specified.</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<dl class="last docutils">
<dt><a class="reference internal" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.edges_iter" title="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.edges_iter"><code class="xref py py-obj docutils literal"><span class="pre">edges_iter</span></code></a></dt>
<dd>return an iterator over the edges</dd>
</dl>
</div>
<p class="rubric">Notes</p>
<p>Nodes in nbunch that are not in the graph will be (quietly) ignored.
For directed graphs this returns the out-edges.</p>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">G</span> <span class="o">=</span> <span class="n">nx</span><span class="o">.</span><span class="n">Graph</span><span class="p">()</span>   <span class="c1"># or DiGraph, MultiGraph, MultiDiGraph, etc</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_path</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_edge</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">,</span><span class="n">weight</span><span class="o">=</span><span class="mi">5</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">edges</span><span class="p">()</span>
<span class="go">[(0, 1), (1, 2), (2, 3)]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">edges</span><span class="p">(</span><span class="n">data</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span> <span class="c1"># default edge data is {} (empty dictionary)</span>
<span class="go">[(0, 1, {}), (1, 2, {}), (2, 3, {&#39;weight&#39;: 5})]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">list</span><span class="p">(</span><span class="n">G</span><span class="o">.</span><span class="n">edges_iter</span><span class="p">(</span><span class="n">data</span><span class="o">=</span><span class="s1">&#39;weight&#39;</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="mi">1</span><span class="p">))</span>
<span class="go">[(0, 1, 1), (1, 2, 1), (2, 3, 5)]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">edges</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span><span class="mi">3</span><span class="p">])</span>
<span class="go">[(0, 1), (3, 2)]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">edges</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
<span class="go">[(0, 1)]</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.edges_iter">
<code class="descname">edges_iter</code><span class="sig-paren">(</span><em>nbunch=None</em>, <em>data=False</em>, <em>default=None</em><span class="sig-paren">)</span><a class="headerlink" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.edges_iter" title="Permalink to this definition">¶</a></dt>
<dd><p>Return an iterator over the edges.</p>
<p>Edges are returned as tuples with optional data
in the order (node, neighbor, data).</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>nbunch</strong> : iterable container, optional (default= all nodes)</p>
<blockquote>
<div><p>A container of nodes.  The container will be iterated
through once.</p>
</div></blockquote>
<p><strong>data</strong> : string or bool, optional (default=False)</p>
<blockquote>
<div><p>The edge attribute returned in 3-tuple (u,v,ddict[data]).
If True, return edge attribute dict in 3-tuple (u,v,ddict).
If False, return 2-tuple (u,v).</p>
</div></blockquote>
<p><strong>default</strong> : value, optional (default=None)</p>
<blockquote>
<div><p>Value used for edges that dont have the requested attribute.
Only relevant if data is not True or False.</p>
</div></blockquote>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><strong>edge_iter</strong> : iterator</p>
<blockquote class="last">
<div><p>An iterator of (u,v) or (u,v,d) tuples of edges.</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<dl class="last docutils">
<dt><a class="reference internal" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.edges" title="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.edges"><code class="xref py py-obj docutils literal"><span class="pre">edges</span></code></a></dt>
<dd>return a list of edges</dd>
</dl>
</div>
<p class="rubric">Notes</p>
<p>Nodes in nbunch that are not in the graph will be (quietly) ignored.
For directed graphs this returns the out-edges.</p>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">G</span> <span class="o">=</span> <span class="n">nx</span><span class="o">.</span><span class="n">DiGraph</span><span class="p">()</span>   <span class="c1"># or MultiDiGraph, etc</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_path</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_edge</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">,</span><span class="n">weight</span><span class="o">=</span><span class="mi">5</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">[</span><span class="n">e</span> <span class="k">for</span> <span class="n">e</span> <span class="ow">in</span> <span class="n">G</span><span class="o">.</span><span class="n">edges_iter</span><span class="p">()]</span>
<span class="go">[(0, 1), (1, 2), (2, 3)]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">list</span><span class="p">(</span><span class="n">G</span><span class="o">.</span><span class="n">edges_iter</span><span class="p">(</span><span class="n">data</span><span class="o">=</span><span class="kc">True</span><span class="p">))</span> <span class="c1"># default data is {} (empty dict)</span>
<span class="go">[(0, 1, {}), (1, 2, {}), (2, 3, {&#39;weight&#39;: 5})]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">list</span><span class="p">(</span><span class="n">G</span><span class="o">.</span><span class="n">edges_iter</span><span class="p">(</span><span class="n">data</span><span class="o">=</span><span class="s1">&#39;weight&#39;</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="mi">1</span><span class="p">))</span> 
<span class="go">[(0, 1, 1), (1, 2, 1), (2, 3, 5)]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">list</span><span class="p">(</span><span class="n">G</span><span class="o">.</span><span class="n">edges_iter</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span><span class="mi">2</span><span class="p">]))</span>
<span class="go">[(0, 1), (2, 3)]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">list</span><span class="p">(</span><span class="n">G</span><span class="o">.</span><span class="n">edges_iter</span><span class="p">(</span><span class="mi">0</span><span class="p">))</span>
<span class="go">[(0, 1)]</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.get_cpds">
<code class="descname">get_cpds</code><span class="sig-paren">(</span><em>node=None</em>, <em>time_slice=0</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/DynamicBayesianNetwork.html#DynamicBayesianNetwork.get_cpds"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.get_cpds" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the CPDs that have been associated with the network.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>node: tuple (node_name, time_slice)</strong></p>
<blockquote>
<div><p>The node should be in the following form (node_name, time_slice).
Here, node_name is the node that is inserted while the time_slice is
an integer value, which denotes the index of the time_slice that the
node belongs to.</p>
</div></blockquote>
<p><strong>time_slice: int</strong></p>
<blockquote class="last">
<div><p>The time_slice should be a positive integer greater than or equal to zero.</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">DynamicBayesianNetwork</span> <span class="k">as</span> <span class="n">DBN</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.factors.discrete</span> <span class="k">import</span> <span class="n">TabularCPD</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dbn</span> <span class="o">=</span> <span class="n">DBN</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dbn</span><span class="o">.</span><span class="n">add_edges_from</span><span class="p">([((</span><span class="s1">&#39;D&#39;</span><span class="p">,</span><span class="mi">0</span><span class="p">),(</span><span class="s1">&#39;G&#39;</span><span class="p">,</span><span class="mi">0</span><span class="p">)),((</span><span class="s1">&#39;I&#39;</span><span class="p">,</span><span class="mi">0</span><span class="p">),(</span><span class="s1">&#39;G&#39;</span><span class="p">,</span><span class="mi">0</span><span class="p">)),((</span><span class="s1">&#39;D&#39;</span><span class="p">,</span><span class="mi">0</span><span class="p">),(</span><span class="s1">&#39;D&#39;</span><span class="p">,</span><span class="mi">1</span><span class="p">)),((</span><span class="s1">&#39;I&#39;</span><span class="p">,</span><span class="mi">0</span><span class="p">),(</span><span class="s1">&#39;I&#39;</span><span class="p">,</span><span class="mi">1</span><span class="p">))])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">grade_cpd</span> <span class="o">=</span>  <span class="n">TabularCPD</span><span class="p">((</span><span class="s1">&#39;G&#39;</span><span class="p">,</span><span class="mi">0</span><span class="p">),</span> <span class="mi">3</span><span class="p">,</span> <span class="p">[[</span><span class="mf">0.3</span><span class="p">,</span><span class="mf">0.05</span><span class="p">,</span><span class="mf">0.9</span><span class="p">,</span><span class="mf">0.5</span><span class="p">],</span>
<span class="gp">... </span>                                     <span class="p">[</span><span class="mf">0.4</span><span class="p">,</span><span class="mf">0.25</span><span class="p">,</span><span class="mf">0.8</span><span class="p">,</span><span class="mf">0.03</span><span class="p">],</span>
<span class="gp">... </span>                                     <span class="p">[</span><span class="mf">0.3</span><span class="p">,</span><span class="mf">0.7</span><span class="p">,</span><span class="mf">0.02</span><span class="p">,</span><span class="mf">0.2</span><span class="p">]],</span> <span class="p">[(</span><span class="s1">&#39;I&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">),(</span><span class="s1">&#39;D&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">)],[</span><span class="mi">2</span><span class="p">,</span><span class="mi">2</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dbn</span><span class="o">.</span><span class="n">add_cpds</span><span class="p">(</span><span class="n">grade_cpd</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dbn</span><span class="o">.</span><span class="n">get_cpds</span><span class="p">()</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.get_edge_data">
<code class="descname">get_edge_data</code><span class="sig-paren">(</span><em>u</em>, <em>v</em>, <em>default=None</em><span class="sig-paren">)</span><a class="headerlink" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.get_edge_data" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the attribute dictionary associated with edge (u,v).</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>u, v</strong> : nodes</p>
<p><strong>default:  any Python object (default=None)</strong></p>
<blockquote>
<div><p>Value to return if the edge (u,v) is not found.</p>
</div></blockquote>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><strong>edge_dict</strong> : dictionary</p>
<blockquote class="last">
<div><p>The edge attribute dictionary.</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Notes</p>
<p>It is faster to use G[u][v].</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">G</span> <span class="o">=</span> <span class="n">nx</span><span class="o">.</span><span class="n">Graph</span><span class="p">()</span>   <span class="c1"># or DiGraph, MultiGraph, MultiDiGraph, etc</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_path</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span>
<span class="go">{}</span>
</pre></div>
</div>
<p>Warning: Assigning G[u][v] corrupts the graph data structure.
But it is safe to assign attributes to that dictionary,</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="mi">1</span><span class="p">][</span><span class="s1">&#39;weight&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="mi">7</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="mi">1</span><span class="p">][</span><span class="s1">&#39;weight&#39;</span><span class="p">]</span>
<span class="go">7</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="p">[</span><span class="mi">1</span><span class="p">][</span><span class="mi">0</span><span class="p">][</span><span class="s1">&#39;weight&#39;</span><span class="p">]</span>
<span class="go">7</span>
</pre></div>
</div>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">G</span> <span class="o">=</span> <span class="n">nx</span><span class="o">.</span><span class="n">Graph</span><span class="p">()</span>   <span class="c1"># or DiGraph, MultiGraph, MultiDiGraph, etc</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_path</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">get_edge_data</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">)</span> <span class="c1"># default edge data is {}</span>
<span class="go">{}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">e</span> <span class="o">=</span> <span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">get_edge_data</span><span class="p">(</span><span class="o">*</span><span class="n">e</span><span class="p">)</span> <span class="c1"># tuple form</span>
<span class="go">{}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">get_edge_data</span><span class="p">(</span><span class="s1">&#39;a&#39;</span><span class="p">,</span><span class="s1">&#39;b&#39;</span><span class="p">,</span><span class="n">default</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span> <span class="c1"># edge not in graph, return 0</span>
<span class="go">0</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.get_inter_edges">
<code class="descname">get_inter_edges</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/DynamicBayesianNetwork.html#DynamicBayesianNetwork.get_inter_edges"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.get_inter_edges" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the inter-slice edges present in the 2-TBN.</p>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">DynamicBayesianNetwork</span> <span class="k">as</span> <span class="n">DBN</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dbn</span> <span class="o">=</span> <span class="n">DBN</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dbn</span><span class="o">.</span><span class="n">add_edges_from</span><span class="p">([((</span><span class="s1">&#39;D&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;G&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">)),</span> <span class="p">((</span><span class="s1">&#39;I&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;G&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">)),</span>
<span class="gp">... </span>                    <span class="p">((</span><span class="s1">&#39;G&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;L&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">)),</span> <span class="p">((</span><span class="s1">&#39;D&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;D&#39;</span><span class="p">,</span> <span class="mi">1</span><span class="p">)),</span>
<span class="gp">... </span>                    <span class="p">((</span><span class="s1">&#39;I&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;I&#39;</span><span class="p">,</span> <span class="mi">1</span><span class="p">)),</span> <span class="p">((</span><span class="s1">&#39;G&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;G&#39;</span><span class="p">,</span> <span class="mi">1</span><span class="p">)),</span>
<span class="gp">... </span>                    <span class="p">((</span><span class="s1">&#39;G&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;L&#39;</span><span class="p">,</span> <span class="mi">1</span><span class="p">)),</span> <span class="p">((</span><span class="s1">&#39;L&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;L&#39;</span><span class="p">,</span> <span class="mi">1</span><span class="p">))])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dbn</span><span class="o">.</span><span class="n">get_inter_edges</span><span class="p">()</span>
<span class="go">[((&#39;D&#39;, 0), (&#39;D&#39;, 1)),</span>
<span class="go"> ((&#39;G&#39;, 0), (&#39;G&#39;, 1)),</span>
<span class="go"> ((&#39;G&#39;, 0), (&#39;L&#39;, 1)),</span>
<span class="go"> ((&#39;I&#39;, 0), (&#39;I&#39;, 1)),</span>
<span class="go"> ((&#39;L&#39;, 0), (&#39;L&#39;, 1))]</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.get_interface_nodes">
<code class="descname">get_interface_nodes</code><span class="sig-paren">(</span><em>time_slice=0</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/DynamicBayesianNetwork.html#DynamicBayesianNetwork.get_interface_nodes"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.get_interface_nodes" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the nodes in the first timeslice whose children are present in the first timeslice.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>time_slice:int</strong></p>
<blockquote class="last">
<div><p>The timeslice should be a positive value greater than or equal to zero</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">DynamicBayesianNetwork</span> <span class="k">as</span> <span class="n">DBN</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dbn</span> <span class="o">=</span> <span class="n">DBN</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dbn</span><span class="o">.</span><span class="n">add_nodes_from</span><span class="p">([</span><span class="s1">&#39;D&#39;</span><span class="p">,</span> <span class="s1">&#39;G&#39;</span><span class="p">,</span> <span class="s1">&#39;I&#39;</span><span class="p">,</span> <span class="s1">&#39;S&#39;</span><span class="p">,</span> <span class="s1">&#39;L&#39;</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dbn</span><span class="o">.</span><span class="n">add_edges_from</span><span class="p">([((</span><span class="s1">&#39;D&#39;</span><span class="p">,</span><span class="mi">0</span><span class="p">),(</span><span class="s1">&#39;G&#39;</span><span class="p">,</span><span class="mi">0</span><span class="p">)),((</span><span class="s1">&#39;I&#39;</span><span class="p">,</span><span class="mi">0</span><span class="p">),(</span><span class="s1">&#39;G&#39;</span><span class="p">,</span><span class="mi">0</span><span class="p">)),((</span><span class="s1">&#39;G&#39;</span><span class="p">,</span><span class="mi">0</span><span class="p">),(</span><span class="s1">&#39;L&#39;</span><span class="p">,</span><span class="mi">0</span><span class="p">)),((</span><span class="s1">&#39;D&#39;</span><span class="p">,</span><span class="mi">0</span><span class="p">),(</span><span class="s1">&#39;D&#39;</span><span class="p">,</span><span class="mi">1</span><span class="p">))])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dbn</span><span class="o">.</span><span class="n">get_interface_nodes</span><span class="p">()</span>
<span class="go">[(&#39;D&#39;, 0)]</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.get_intra_edges">
<code class="descname">get_intra_edges</code><span class="sig-paren">(</span><em>time_slice=0</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/DynamicBayesianNetwork.html#DynamicBayesianNetwork.get_intra_edges"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.get_intra_edges" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the intra slice edges present in the 2-TBN.</p>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">DynamicBayesianNetwork</span> <span class="k">as</span> <span class="n">DBN</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dbn</span> <span class="o">=</span> <span class="n">DBN</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dbn</span><span class="o">.</span><span class="n">add_nodes_from</span><span class="p">([</span><span class="s1">&#39;D&#39;</span><span class="p">,</span> <span class="s1">&#39;G&#39;</span><span class="p">,</span> <span class="s1">&#39;I&#39;</span><span class="p">,</span> <span class="s1">&#39;S&#39;</span><span class="p">,</span> <span class="s1">&#39;L&#39;</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dbn</span><span class="o">.</span><span class="n">add_edges_from</span><span class="p">([((</span><span class="s1">&#39;D&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;G&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">)),</span> <span class="p">((</span><span class="s1">&#39;I&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;G&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">)),</span>
<span class="gp">... </span>                    <span class="p">((</span><span class="s1">&#39;G&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;L&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">)),</span> <span class="p">((</span><span class="s1">&#39;D&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;D&#39;</span><span class="p">,</span> <span class="mi">1</span><span class="p">)),</span>
<span class="gp">... </span>                    <span class="p">((</span><span class="s1">&#39;I&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;I&#39;</span><span class="p">,</span> <span class="mi">1</span><span class="p">)),</span> <span class="p">((</span><span class="s1">&#39;G&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;G&#39;</span><span class="p">,</span> <span class="mi">1</span><span class="p">)),</span>
<span class="gp">... </span>                    <span class="p">((</span><span class="s1">&#39;G&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;L&#39;</span><span class="p">,</span> <span class="mi">1</span><span class="p">)),</span> <span class="p">((</span><span class="s1">&#39;L&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;L&#39;</span><span class="p">,</span> <span class="mi">1</span><span class="p">))])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dbn</span><span class="o">.</span><span class="n">get_intra_edges</span><span class="p">()</span>
<span class="go">[((&#39;D&#39;, 0), (&#39;G&#39;, 0)), ((&#39;G&#39;, 0), (&#39;L&#39;, 0)), ((&#39;I&#39;, 0), (&#39;G&#39;, 0))</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.get_leaves">
<code class="descname">get_leaves</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.get_leaves" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns a list of leaves of the graph.</p>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.base</span> <span class="k">import</span> <span class="n">DirectedGraph</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">graph</span> <span class="o">=</span> <span class="n">DirectedGraph</span><span class="p">([(</span><span class="s1">&#39;A&#39;</span><span class="p">,</span> <span class="s1">&#39;B&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;B&#39;</span><span class="p">,</span> <span class="s1">&#39;C&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;B&#39;</span><span class="p">,</span> <span class="s1">&#39;D&#39;</span><span class="p">)])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">graph</span><span class="o">.</span><span class="n">get_leaves</span><span class="p">()</span>
<span class="go">[&#39;C&#39;, &#39;D&#39;]</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.get_parents">
<code class="descname">get_parents</code><span class="sig-paren">(</span><em>node</em><span class="sig-paren">)</span><a class="headerlink" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.get_parents" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns a list of parents of node.</p>
<p>Throws an error if the node is not present in the graph.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>node: string, int or any hashable python object.</strong></p>
<blockquote class="last">
<div><p>The node whose parents would be returned.</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.base</span> <span class="k">import</span> <span class="n">DirectedGraph</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span> <span class="o">=</span> <span class="n">DirectedGraph</span><span class="p">(</span><span class="n">ebunch</span><span class="o">=</span><span class="p">[(</span><span class="s1">&#39;diff&#39;</span><span class="p">,</span> <span class="s1">&#39;grade&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;intel&#39;</span><span class="p">,</span> <span class="s1">&#39;grade&#39;</span><span class="p">)])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">parents</span><span class="p">(</span><span class="n">node</span><span class="o">=</span><span class="s1">&#39;grade&#39;</span><span class="p">)</span>
<span class="go">[&#39;diff&#39;, &#39;intel&#39;]</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.get_roots">
<code class="descname">get_roots</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.get_roots" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns a list of roots of the graph.</p>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.base</span> <span class="k">import</span> <span class="n">DirectedGraph</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">graph</span> <span class="o">=</span> <span class="n">DirectedGraph</span><span class="p">([(</span><span class="s1">&#39;A&#39;</span><span class="p">,</span> <span class="s1">&#39;B&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;B&#39;</span><span class="p">,</span> <span class="s1">&#39;C&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;B&#39;</span><span class="p">,</span> <span class="s1">&#39;D&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;E&#39;</span><span class="p">,</span> <span class="s1">&#39;B&#39;</span><span class="p">)])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">graph</span><span class="o">.</span><span class="n">get_roots</span><span class="p">()</span>
<span class="go">[&#39;A&#39;, &#39;E&#39;]</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.get_slice_nodes">
<code class="descname">get_slice_nodes</code><span class="sig-paren">(</span><em>time_slice=0</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/DynamicBayesianNetwork.html#DynamicBayesianNetwork.get_slice_nodes"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.get_slice_nodes" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the nodes present in a particular timeslice</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>time_slice:int</strong></p>
<blockquote class="last">
<div><p>The timeslice should be a positive value greater than or equal to zero</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">DynamicBayesianNetwork</span> <span class="k">as</span> <span class="n">DBN</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dbn</span> <span class="o">=</span> <span class="n">DBN</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dbn</span><span class="o">.</span><span class="n">add_nodes_from</span><span class="p">([</span><span class="s1">&#39;D&#39;</span><span class="p">,</span> <span class="s1">&#39;G&#39;</span><span class="p">,</span> <span class="s1">&#39;I&#39;</span><span class="p">,</span> <span class="s1">&#39;S&#39;</span><span class="p">,</span> <span class="s1">&#39;L&#39;</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dbn</span><span class="o">.</span><span class="n">add_edges_from</span><span class="p">([((</span><span class="s1">&#39;D&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">),(</span><span class="s1">&#39;G&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">)),((</span><span class="s1">&#39;I&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">),(</span><span class="s1">&#39;G&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">)),((</span><span class="s1">&#39;G&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">),(</span><span class="s1">&#39;L&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">)),((</span><span class="s1">&#39;D&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">),(</span><span class="s1">&#39;D&#39;</span><span class="p">,</span> <span class="mi">1</span><span class="p">))])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dbn</span><span class="o">.</span><span class="n">get_slice_nodes</span><span class="p">()</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.has_edge">
<code class="descname">has_edge</code><span class="sig-paren">(</span><em>u</em>, <em>v</em><span class="sig-paren">)</span><a class="headerlink" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.has_edge" title="Permalink to this definition">¶</a></dt>
<dd><p>Return True if the edge (u,v) is in the graph.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>u, v</strong> : nodes</p>
<blockquote>
<div><p>Nodes can be, for example, strings or numbers.
Nodes must be hashable (and not None) Python objects.</p>
</div></blockquote>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><strong>edge_ind</strong> : bool</p>
<blockquote class="last">
<div><p>True if edge is in the graph, False otherwise.</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<p>Can be called either using two nodes u,v or edge tuple (u,v)</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">G</span> <span class="o">=</span> <span class="n">nx</span><span class="o">.</span><span class="n">Graph</span><span class="p">()</span>   <span class="c1"># or DiGraph, MultiGraph, MultiDiGraph, etc</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_path</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">has_edge</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">)</span>  <span class="c1"># using two nodes</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">e</span> <span class="o">=</span> <span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">has_edge</span><span class="p">(</span><span class="o">*</span><span class="n">e</span><span class="p">)</span>  <span class="c1">#  e is a 2-tuple (u,v)</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">e</span> <span class="o">=</span> <span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">,{</span><span class="s1">&#39;weight&#39;</span><span class="p">:</span><span class="mi">7</span><span class="p">})</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">has_edge</span><span class="p">(</span><span class="o">*</span><span class="n">e</span><span class="p">[:</span><span class="mi">2</span><span class="p">])</span>  <span class="c1"># e is a 3-tuple (u,v,data_dictionary)</span>
<span class="go">True</span>
</pre></div>
</div>
<p>The following syntax are all equivalent:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">has_edge</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">)</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="mi">1</span> <span class="ow">in</span> <span class="n">G</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>  <span class="c1"># though this gives KeyError if 0 not in G</span>
<span class="go">True</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.has_node">
<code class="descname">has_node</code><span class="sig-paren">(</span><em>n</em><span class="sig-paren">)</span><a class="headerlink" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.has_node" title="Permalink to this definition">¶</a></dt>
<dd><p>Return True if the graph contains the node n.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>n</strong> : node</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">G</span> <span class="o">=</span> <span class="n">nx</span><span class="o">.</span><span class="n">Graph</span><span class="p">()</span>   <span class="c1"># or DiGraph, MultiGraph, MultiDiGraph, etc</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_path</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">has_node</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
<span class="go">True</span>
</pre></div>
</div>
<p>It is more readable and simpler to use</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="mi">0</span> <span class="ow">in</span> <span class="n">G</span>
<span class="go">True</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.has_predecessor">
<code class="descname">has_predecessor</code><span class="sig-paren">(</span><em>u</em>, <em>v</em><span class="sig-paren">)</span><a class="headerlink" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.has_predecessor" title="Permalink to this definition">¶</a></dt>
<dd><p>Return True if node u has predecessor v.</p>
<p>This is true if graph has the edge u&lt;-v.</p>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.has_successor">
<code class="descname">has_successor</code><span class="sig-paren">(</span><em>u</em>, <em>v</em><span class="sig-paren">)</span><a class="headerlink" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.has_successor" title="Permalink to this definition">¶</a></dt>
<dd><p>Return True if node u has successor v.</p>
<p>This is true if graph has the edge u-&gt;v.</p>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.in_degree">
<code class="descname">in_degree</code><span class="sig-paren">(</span><em>nbunch=None</em>, <em>weight=None</em><span class="sig-paren">)</span><a class="headerlink" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.in_degree" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the in-degree of a node or nodes.</p>
<p>The node in-degree is the number of edges pointing in to the node.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>nbunch</strong> : iterable container, optional (default=all nodes)</p>
<blockquote>
<div><p>A container of nodes.  The container will be iterated
through once.</p>
</div></blockquote>
<p><strong>weight</strong> : string or None, optional (default=None)</p>
<blockquote>
<div><p>The edge attribute that holds the numerical value used
as a weight.  If None, then each edge has weight 1.
The degree is the sum of the edge weights adjacent to the node.</p>
</div></blockquote>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><strong>nd</strong> : dictionary, or number</p>
<blockquote class="last">
<div><p>A dictionary with nodes as keys and in-degree as values or
a number if a single node is specified.</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.degree" title="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.degree"><code class="xref py py-obj docutils literal"><span class="pre">degree</span></code></a>, <a class="reference internal" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.out_degree" title="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.out_degree"><code class="xref py py-obj docutils literal"><span class="pre">out_degree</span></code></a>, <a class="reference internal" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.in_degree_iter" title="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.in_degree_iter"><code class="xref py py-obj docutils literal"><span class="pre">in_degree_iter</span></code></a></p>
</div>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">G</span> <span class="o">=</span> <span class="n">nx</span><span class="o">.</span><span class="n">DiGraph</span><span class="p">()</span>   <span class="c1"># or MultiDiGraph</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_path</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">in_degree</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
<span class="go">0</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">in_degree</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">])</span>
<span class="go">{0: 0, 1: 1}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">list</span><span class="p">(</span><span class="n">G</span><span class="o">.</span><span class="n">in_degree</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">])</span><span class="o">.</span><span class="n">values</span><span class="p">())</span>
<span class="go">[0, 1]</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.in_degree_iter">
<code class="descname">in_degree_iter</code><span class="sig-paren">(</span><em>nbunch=None</em>, <em>weight=None</em><span class="sig-paren">)</span><a class="headerlink" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.in_degree_iter" title="Permalink to this definition">¶</a></dt>
<dd><p>Return an iterator for (node, in-degree).</p>
<p>The node in-degree is the number of edges pointing in to the node.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>nbunch</strong> : iterable container, optional (default=all nodes)</p>
<blockquote>
<div><p>A container of nodes.  The container will be iterated
through once.</p>
</div></blockquote>
<p><strong>weight</strong> : string or None, optional (default=None)</p>
<blockquote>
<div><p>The edge attribute that holds the numerical value used
as a weight.  If None, then each edge has weight 1.
The degree is the sum of the edge weights adjacent to the node.</p>
</div></blockquote>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><strong>nd_iter</strong> : an iterator</p>
<blockquote class="last">
<div><p>The iterator returns two-tuples of (node, in-degree).</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.degree" title="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.degree"><code class="xref py py-obj docutils literal"><span class="pre">degree</span></code></a>, <a class="reference internal" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.in_degree" title="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.in_degree"><code class="xref py py-obj docutils literal"><span class="pre">in_degree</span></code></a>, <a class="reference internal" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.out_degree" title="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.out_degree"><code class="xref py py-obj docutils literal"><span class="pre">out_degree</span></code></a>, <a class="reference internal" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.out_degree_iter" title="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.out_degree_iter"><code class="xref py py-obj docutils literal"><span class="pre">out_degree_iter</span></code></a></p>
</div>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">G</span> <span class="o">=</span> <span class="n">nx</span><span class="o">.</span><span class="n">DiGraph</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_path</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">list</span><span class="p">(</span><span class="n">G</span><span class="o">.</span><span class="n">in_degree_iter</span><span class="p">(</span><span class="mi">0</span><span class="p">))</span> <span class="c1"># node 0 with degree 0</span>
<span class="go">[(0, 0)]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">list</span><span class="p">(</span><span class="n">G</span><span class="o">.</span><span class="n">in_degree_iter</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">]))</span>
<span class="go">[(0, 0), (1, 1)]</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.in_edges">
<code class="descname">in_edges</code><span class="sig-paren">(</span><em>nbunch=None</em>, <em>data=False</em><span class="sig-paren">)</span><a class="headerlink" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.in_edges" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a list of the incoming edges.</p>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<dl class="last docutils">
<dt><a class="reference internal" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.edges" title="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.edges"><code class="xref py py-obj docutils literal"><span class="pre">edges</span></code></a></dt>
<dd>return a list of edges</dd>
</dl>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.in_edges_iter">
<code class="descname">in_edges_iter</code><span class="sig-paren">(</span><em>nbunch=None</em>, <em>data=False</em><span class="sig-paren">)</span><a class="headerlink" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.in_edges_iter" title="Permalink to this definition">¶</a></dt>
<dd><p>Return an iterator over the incoming edges.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>nbunch</strong> : iterable container, optional (default= all nodes)</p>
<blockquote>
<div><p>A container of nodes.  The container will be iterated
through once.</p>
</div></blockquote>
<p><strong>data</strong> : bool, optional (default=False)</p>
<blockquote>
<div><p>If True, return edge attribute dict in 3-tuple (u,v,data).</p>
</div></blockquote>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><strong>in_edge_iter</strong> : iterator</p>
<blockquote class="last">
<div><p>An iterator of (u,v) or (u,v,d) tuples of incoming edges.</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<dl class="last docutils">
<dt><a class="reference internal" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.edges_iter" title="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.edges_iter"><code class="xref py py-obj docutils literal"><span class="pre">edges_iter</span></code></a></dt>
<dd>return an iterator of edges</dd>
</dl>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.initialize_initial_state">
<code class="descname">initialize_initial_state</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/DynamicBayesianNetwork.html#DynamicBayesianNetwork.initialize_initial_state"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.initialize_initial_state" title="Permalink to this definition">¶</a></dt>
<dd><p>This method will automatically re-adjust the cpds and the edges added to the bayesian network.
If an edge that is added as an intra time slice edge in the 0th timeslice, this method will
automatically add it in the 1st timeslice. It will also add the cpds. However, to call this
method, one needs to add cpds as well as the edges in the bayesian network of the whole
skeleton including the 0th and the 1st timeslice,.</p>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">DynamicBayesianNetwork</span> <span class="k">as</span> <span class="n">DBN</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.factors.discrete</span> <span class="k">import</span> <span class="n">TabularCPD</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">student</span> <span class="o">=</span> <span class="n">DBN</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">student</span><span class="o">.</span><span class="n">add_nodes_from</span><span class="p">([</span><span class="s1">&#39;D&#39;</span><span class="p">,</span> <span class="s1">&#39;G&#39;</span><span class="p">,</span> <span class="s1">&#39;I&#39;</span><span class="p">,</span> <span class="s1">&#39;S&#39;</span><span class="p">,</span> <span class="s1">&#39;L&#39;</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">student</span><span class="o">.</span><span class="n">add_edges_from</span><span class="p">([((</span><span class="s1">&#39;D&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">),(</span><span class="s1">&#39;G&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">)),((</span><span class="s1">&#39;I&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">),(</span><span class="s1">&#39;G&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">)),((</span><span class="s1">&#39;D&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">),(</span><span class="s1">&#39;D&#39;</span><span class="p">,</span> <span class="mi">1</span><span class="p">)),((</span><span class="s1">&#39;I&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">),(</span><span class="s1">&#39;I&#39;</span><span class="p">,</span> <span class="mi">1</span><span class="p">))])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">grade_cpd</span> <span class="o">=</span> <span class="n">TabularCPD</span><span class="p">((</span><span class="s1">&#39;G&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span> <span class="mi">3</span><span class="p">,</span> <span class="p">[[</span><span class="mf">0.3</span><span class="p">,</span> <span class="mf">0.05</span><span class="p">,</span> <span class="mf">0.9</span><span class="p">,</span> <span class="mf">0.5</span><span class="p">],</span>
<span class="gp">... </span>                                     <span class="p">[</span><span class="mf">0.4</span><span class="p">,</span> <span class="mf">0.25</span><span class="p">,</span> <span class="mf">0.8</span><span class="p">,</span> <span class="mf">0.03</span><span class="p">],</span>
<span class="gp">... </span>                                     <span class="p">[</span><span class="mf">0.3</span><span class="p">,</span> <span class="mf">0.7</span><span class="p">,</span> <span class="mf">0.02</span><span class="p">,</span> <span class="mf">0.2</span><span class="p">]],</span>
<span class="gp">... </span>                       <span class="n">evidence</span><span class="o">=</span><span class="p">[(</span><span class="s1">&#39;I&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">),(</span><span class="s1">&#39;D&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">)],</span>
<span class="gp">... </span>                       <span class="n">evidence_card</span><span class="o">=</span><span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">d_i_cpd</span> <span class="o">=</span> <span class="n">TabularCPD</span><span class="p">((</span><span class="s1">&#39;D&#39;</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span> <span class="mi">2</span><span class="p">,</span> <span class="p">[[</span><span class="mf">0.6</span><span class="p">,</span> <span class="mf">0.3</span><span class="p">],</span>
<span class="gp">... </span>                                   <span class="p">[</span><span class="mf">0.4</span><span class="p">,</span> <span class="mf">0.7</span><span class="p">]],</span>
<span class="gp">... </span>                     <span class="n">evidence</span><span class="o">=</span><span class="p">[(</span><span class="s1">&#39;D&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">)],</span>
<span class="gp">... </span>                     <span class="n">evidence_card</span><span class="o">=</span><span class="mi">2</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">diff_cpd</span> <span class="o">=</span> <span class="n">TabularCPD</span><span class="p">((</span><span class="s1">&#39;D&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span> <span class="mi">2</span><span class="p">,</span> <span class="p">[[</span><span class="mf">0.6</span><span class="p">,</span> <span class="mf">0.4</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">intel_cpd</span> <span class="o">=</span> <span class="n">TabularCPD</span><span class="p">((</span><span class="s1">&#39;I&#39;</span><span class="p">,</span><span class="mi">0</span><span class="p">),</span> <span class="mi">2</span><span class="p">,</span> <span class="p">[[</span><span class="mf">0.7</span><span class="p">,</span> <span class="mf">0.3</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">i_i_cpd</span> <span class="o">=</span> <span class="n">TabularCPD</span><span class="p">((</span><span class="s1">&#39;I&#39;</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span> <span class="mi">2</span><span class="p">,</span> <span class="p">[[</span><span class="mf">0.5</span><span class="p">,</span> <span class="mf">0.4</span><span class="p">],</span>
<span class="gp">... </span>                                   <span class="p">[</span><span class="mf">0.5</span><span class="p">,</span> <span class="mf">0.6</span><span class="p">]],</span>
<span class="gp">... </span>                     <span class="n">evidence</span><span class="o">=</span><span class="p">[(</span><span class="s1">&#39;I&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">)],</span>
<span class="gp">... </span>                     <span class="n">evidence_card</span><span class="o">=</span><span class="mi">2</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">student</span><span class="o">.</span><span class="n">add_cpds</span><span class="p">(</span><span class="n">grade_cpd</span><span class="p">,</span> <span class="n">d_i_cpd</span><span class="p">,</span> <span class="n">diff_cpd</span><span class="p">,</span> <span class="n">intel_cpd</span><span class="p">,</span> <span class="n">i_i_cpd</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">student</span><span class="o">.</span><span class="n">initialize_initial_state</span><span class="p">()</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.is_directed">
<code class="descname">is_directed</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.is_directed" title="Permalink to this definition">¶</a></dt>
<dd><p>Return True if graph is directed, False otherwise.</p>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.is_multigraph">
<code class="descname">is_multigraph</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.is_multigraph" title="Permalink to this definition">¶</a></dt>
<dd><p>Return True if graph is a multigraph, False otherwise.</p>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.moralize">
<code class="descname">moralize</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/DynamicBayesianNetwork.html#DynamicBayesianNetwork.moralize"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.moralize" title="Permalink to this definition">¶</a></dt>
<dd><p>Removes all the immoralities in the Network and creates a moral
graph (UndirectedGraph).</p>
<p>A v-structure X-&gt;Z&lt;-Y is an immorality if there is no directed edge
between X and Y.</p>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">DynamicBayesianNetwork</span> <span class="k">as</span> <span class="n">DBN</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dbn</span> <span class="o">=</span> <span class="n">DBN</span><span class="p">([((</span><span class="s1">&#39;D&#39;</span><span class="p">,</span><span class="mi">0</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;G&#39;</span><span class="p">,</span><span class="mi">0</span><span class="p">)),</span> <span class="p">((</span><span class="s1">&#39;I&#39;</span><span class="p">,</span><span class="mi">0</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;G&#39;</span><span class="p">,</span><span class="mi">0</span><span class="p">))])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">moral_graph</span> <span class="o">=</span> <span class="n">dbn</span><span class="o">.</span><span class="n">moralize</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">moral_graph</span><span class="o">.</span><span class="n">edges</span><span class="p">()</span>
<span class="go">[((&#39;G&#39;, 0), (&#39;I&#39;, 0)),</span>
<span class="go">((&#39;G&#39;, 0), (&#39;D&#39;, 0)),</span>
<span class="go">((&#39;D&#39;, 1), (&#39;I&#39;, 1)),</span>
<span class="go">((&#39;D&#39;, 1), (&#39;G&#39;, 1)),</span>
<span class="go">((&#39;I&#39;, 0), (&#39;D&#39;, 0)),</span>
<span class="go">((&#39;G&#39;, 1), (&#39;I&#39;, 1))]</span>
</pre></div>
</div>
</dd></dl>

<dl class="attribute">
<dt id="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.name">
<code class="descname">name</code><a class="headerlink" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.name" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="method">
<dt id="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.nbunch_iter">
<code class="descname">nbunch_iter</code><span class="sig-paren">(</span><em>nbunch=None</em><span class="sig-paren">)</span><a class="headerlink" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.nbunch_iter" title="Permalink to this definition">¶</a></dt>
<dd><p>Return an iterator of nodes contained in nbunch that are
also in the graph.</p>
<p>The nodes in nbunch are checked for membership in the graph
and if not are silently ignored.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>nbunch</strong> : iterable container, optional (default=all nodes)</p>
<blockquote>
<div><p>A container of nodes.  The container will be iterated
through once.</p>
</div></blockquote>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><strong>niter</strong> : iterator</p>
<blockquote>
<div><p>An iterator over nodes in nbunch that are also in the graph.
If nbunch is None, iterate over all nodes in the graph.</p>
</div></blockquote>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Raises:</th><td class="field-body"><p class="first"><strong>NetworkXError</strong></p>
<blockquote class="last">
<div><p>If nbunch is not a node or or sequence of nodes.
If a node in nbunch is not hashable.</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><code class="xref py py-obj docutils literal"><span class="pre">Graph.__iter__</span></code></p>
</div>
<p class="rubric">Notes</p>
<p>When nbunch is an iterator, the returned iterator yields values
directly from nbunch, becoming exhausted when nbunch is exhausted.</p>
<p>To test whether nbunch is a single node, one can use
&#8220;if nbunch in self:&#8221;, even after processing with this routine.</p>
<p>If nbunch is not a node or a (possibly empty) sequence/iterator
or None, a NetworkXError is raised.  Also, if any object in
nbunch is not hashable, a NetworkXError is raised.</p>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.neighbors">
<code class="descname">neighbors</code><span class="sig-paren">(</span><em>n</em><span class="sig-paren">)</span><a class="headerlink" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.neighbors" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a list of successor nodes of n.</p>
<p>neighbors() and successors() are the same function.</p>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.neighbors_iter">
<code class="descname">neighbors_iter</code><span class="sig-paren">(</span><em>n</em><span class="sig-paren">)</span><a class="headerlink" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.neighbors_iter" title="Permalink to this definition">¶</a></dt>
<dd><p>Return an iterator over successor nodes of n.</p>
<p>neighbors_iter() and successors_iter() are the same.</p>
</dd></dl>

<dl class="attribute">
<dt id="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.node_dict_factory">
<code class="descname">node_dict_factory</code><a class="headerlink" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.node_dict_factory" title="Permalink to this definition">¶</a></dt>
<dd><p>alias of <a class="reference external" href="https://docs.python.org/2/library/stdtypes.html#dict" title="(in Python v2.7)"><code class="xref py py-class docutils literal"><span class="pre">dict</span></code></a></p>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.nodes">
<code class="descname">nodes</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/DynamicBayesianNetwork.html#DynamicBayesianNetwork.nodes"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.nodes" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the list of nodes present in the network</p>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">DynamicBayesianNetwork</span> <span class="k">as</span> <span class="n">DBN</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dbn</span> <span class="o">=</span> <span class="n">DBN</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dbn</span><span class="o">.</span><span class="n">add_nodes_from</span><span class="p">([</span><span class="s1">&#39;A&#39;</span><span class="p">,</span> <span class="s1">&#39;B&#39;</span><span class="p">,</span> <span class="s1">&#39;C&#39;</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dbn</span><span class="o">.</span><span class="n">nodes</span><span class="p">()</span>
<span class="go">[&#39;B&#39;, &#39;A&#39;, &#39;C&#39;]</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.nodes_iter">
<code class="descname">nodes_iter</code><span class="sig-paren">(</span><em>data=False</em><span class="sig-paren">)</span><a class="headerlink" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.nodes_iter" title="Permalink to this definition">¶</a></dt>
<dd><p>Return an iterator over the nodes.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>data</strong> : boolean, optional (default=False)</p>
<blockquote>
<div><p>If False the iterator returns nodes.  If True
return a two-tuple of node and node data dictionary</p>
</div></blockquote>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><strong>niter</strong> : iterator</p>
<blockquote class="last">
<div><p>An iterator over nodes.  If data=True the iterator gives
two-tuples containing (node, node data, dictionary)</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Notes</p>
<p>If the node data is not required it is simpler and equivalent
to use the expression &#8216;for n in G&#8217;.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">G</span> <span class="o">=</span> <span class="n">nx</span><span class="o">.</span><span class="n">Graph</span><span class="p">()</span>   <span class="c1"># or DiGraph, MultiGraph, MultiDiGraph, etc</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_path</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">])</span>
</pre></div>
</div>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">G</span> <span class="o">=</span> <span class="n">nx</span><span class="o">.</span><span class="n">Graph</span><span class="p">()</span>   <span class="c1"># or DiGraph, MultiGraph, MultiDiGraph, etc</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_path</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">])</span>
</pre></div>
</div>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">[</span><span class="n">d</span> <span class="k">for</span> <span class="n">n</span><span class="p">,</span><span class="n">d</span> <span class="ow">in</span> <span class="n">G</span><span class="o">.</span><span class="n">nodes_iter</span><span class="p">(</span><span class="n">data</span><span class="o">=</span><span class="kc">True</span><span class="p">)]</span>
<span class="go">[{}, {}, {}]</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.nodes_with_selfloops">
<code class="descname">nodes_with_selfloops</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.nodes_with_selfloops" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a list of nodes with self loops.</p>
<p>A node with a self loop has an edge with both ends adjacent
to that node.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><strong>nodelist</strong> : list</p>
<blockquote class="last">
<div><p>A list of nodes with self loops.</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.selfloop_edges" title="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.selfloop_edges"><code class="xref py py-obj docutils literal"><span class="pre">selfloop_edges</span></code></a>, <a class="reference internal" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.number_of_selfloops" title="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.number_of_selfloops"><code class="xref py py-obj docutils literal"><span class="pre">number_of_selfloops</span></code></a></p>
</div>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">G</span> <span class="o">=</span> <span class="n">nx</span><span class="o">.</span><span class="n">Graph</span><span class="p">()</span>   <span class="c1"># or DiGraph, MultiGraph, MultiDiGraph, etc</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_edge</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="mi">1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_edge</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">nodes_with_selfloops</span><span class="p">()</span>
<span class="go">[1]</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.number_of_edges">
<code class="descname">number_of_edges</code><span class="sig-paren">(</span><em>u=None</em>, <em>v=None</em><span class="sig-paren">)</span><a class="headerlink" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.number_of_edges" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the number of edges between two nodes.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>u, v</strong> : nodes, optional (default=all edges)</p>
<blockquote>
<div><p>If u and v are specified, return the number of edges between
u and v. Otherwise return the total number of all edges.</p>
</div></blockquote>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><strong>nedges</strong> : int</p>
<blockquote class="last">
<div><p>The number of edges in the graph.  If nodes u and v are specified
return the number of edges between those nodes.</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.size" title="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.size"><code class="xref py py-obj docutils literal"><span class="pre">size</span></code></a></p>
</div>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">G</span> <span class="o">=</span> <span class="n">nx</span><span class="o">.</span><span class="n">Graph</span><span class="p">()</span>   <span class="c1"># or DiGraph, MultiGraph, MultiDiGraph, etc</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_path</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">number_of_edges</span><span class="p">()</span>
<span class="go">3</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">number_of_edges</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">)</span>
<span class="go">1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">e</span> <span class="o">=</span> <span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">number_of_edges</span><span class="p">(</span><span class="o">*</span><span class="n">e</span><span class="p">)</span>
<span class="go">1</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.number_of_nodes">
<code class="descname">number_of_nodes</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.number_of_nodes" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the number of nodes in the graph.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><strong>nnodes</strong> : int</p>
<blockquote class="last">
<div><p>The number of nodes in the graph.</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.order" title="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.order"><code class="xref py py-obj docutils literal"><span class="pre">order</span></code></a>, <code class="xref py py-obj docutils literal"><span class="pre">__len__</span></code></p>
</div>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">G</span> <span class="o">=</span> <span class="n">nx</span><span class="o">.</span><span class="n">Graph</span><span class="p">()</span>   <span class="c1"># or DiGraph, MultiGraph, MultiDiGraph, etc</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_path</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">len</span><span class="p">(</span><span class="n">G</span><span class="p">)</span>
<span class="go">3</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.number_of_selfloops">
<code class="descname">number_of_selfloops</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.number_of_selfloops" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the number of selfloop edges.</p>
<p>A selfloop edge has the same node at both ends.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><strong>nloops</strong> : int</p>
<blockquote class="last">
<div><p>The number of selfloops.</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.nodes_with_selfloops" title="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.nodes_with_selfloops"><code class="xref py py-obj docutils literal"><span class="pre">nodes_with_selfloops</span></code></a>, <a class="reference internal" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.selfloop_edges" title="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.selfloop_edges"><code class="xref py py-obj docutils literal"><span class="pre">selfloop_edges</span></code></a></p>
</div>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">=</span><span class="n">nx</span><span class="o">.</span><span class="n">Graph</span><span class="p">()</span>   <span class="c1"># or DiGraph, MultiGraph, MultiDiGraph, etc</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_edge</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="mi">1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_edge</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">number_of_selfloops</span><span class="p">()</span>
<span class="go">1</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.order">
<code class="descname">order</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.order" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the number of nodes in the graph.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><strong>nnodes</strong> : int</p>
<blockquote class="last">
<div><p>The number of nodes in the graph.</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.number_of_nodes" title="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.number_of_nodes"><code class="xref py py-obj docutils literal"><span class="pre">number_of_nodes</span></code></a>, <code class="xref py py-obj docutils literal"><span class="pre">__len__</span></code></p>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.out_degree">
<code class="descname">out_degree</code><span class="sig-paren">(</span><em>nbunch=None</em>, <em>weight=None</em><span class="sig-paren">)</span><a class="headerlink" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.out_degree" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the out-degree of a node or nodes.</p>
<p>The node out-degree is the number of edges pointing out of the node.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>nbunch</strong> : iterable container, optional (default=all nodes)</p>
<blockquote>
<div><p>A container of nodes.  The container will be iterated
through once.</p>
</div></blockquote>
<p><strong>weight</strong> : string or None, optional (default=None)</p>
<blockquote>
<div><p>The edge attribute that holds the numerical value used
as a weight.  If None, then each edge has weight 1.
The degree is the sum of the edge weights adjacent to the node.</p>
</div></blockquote>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><strong>nd</strong> : dictionary, or number</p>
<blockquote class="last">
<div><p>A dictionary with nodes as keys and out-degree as values or
a number if a single node is specified.</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">G</span> <span class="o">=</span> <span class="n">nx</span><span class="o">.</span><span class="n">DiGraph</span><span class="p">()</span>   <span class="c1"># or MultiDiGraph</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_path</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">out_degree</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
<span class="go">1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">out_degree</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">])</span>
<span class="go">{0: 1, 1: 1}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">list</span><span class="p">(</span><span class="n">G</span><span class="o">.</span><span class="n">out_degree</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">])</span><span class="o">.</span><span class="n">values</span><span class="p">())</span>
<span class="go">[1, 1]</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.out_degree_iter">
<code class="descname">out_degree_iter</code><span class="sig-paren">(</span><em>nbunch=None</em>, <em>weight=None</em><span class="sig-paren">)</span><a class="headerlink" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.out_degree_iter" title="Permalink to this definition">¶</a></dt>
<dd><p>Return an iterator for (node, out-degree).</p>
<p>The node out-degree is the number of edges pointing out of the node.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>nbunch</strong> : iterable container, optional (default=all nodes)</p>
<blockquote>
<div><p>A container of nodes.  The container will be iterated
through once.</p>
</div></blockquote>
<p><strong>weight</strong> : string or None, optional (default=None)</p>
<blockquote>
<div><p>The edge attribute that holds the numerical value used
as a weight.  If None, then each edge has weight 1.
The degree is the sum of the edge weights adjacent to the node.</p>
</div></blockquote>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><strong>nd_iter</strong> : an iterator</p>
<blockquote class="last">
<div><p>The iterator returns two-tuples of (node, out-degree).</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.degree" title="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.degree"><code class="xref py py-obj docutils literal"><span class="pre">degree</span></code></a>, <a class="reference internal" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.in_degree" title="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.in_degree"><code class="xref py py-obj docutils literal"><span class="pre">in_degree</span></code></a>, <a class="reference internal" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.out_degree" title="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.out_degree"><code class="xref py py-obj docutils literal"><span class="pre">out_degree</span></code></a>, <a class="reference internal" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.in_degree_iter" title="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.in_degree_iter"><code class="xref py py-obj docutils literal"><span class="pre">in_degree_iter</span></code></a></p>
</div>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">G</span> <span class="o">=</span> <span class="n">nx</span><span class="o">.</span><span class="n">DiGraph</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_path</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">list</span><span class="p">(</span><span class="n">G</span><span class="o">.</span><span class="n">out_degree_iter</span><span class="p">(</span><span class="mi">0</span><span class="p">))</span> <span class="c1"># node 0 with degree 1</span>
<span class="go">[(0, 1)]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">list</span><span class="p">(</span><span class="n">G</span><span class="o">.</span><span class="n">out_degree_iter</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">]))</span>
<span class="go">[(0, 1), (1, 1)]</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.out_edges">
<code class="descname">out_edges</code><span class="sig-paren">(</span><em>nbunch=None</em>, <em>data=False</em>, <em>default=None</em><span class="sig-paren">)</span><a class="headerlink" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.out_edges" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a list of edges.</p>
<p>Edges are returned as tuples with optional data
in the order (node, neighbor, data).</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>nbunch</strong> : iterable container, optional (default= all nodes)</p>
<blockquote>
<div><p>A container of nodes.  The container will be iterated
through once.</p>
</div></blockquote>
<p><strong>data</strong> : string or bool, optional (default=False)</p>
<blockquote>
<div><p>The edge attribute returned in 3-tuple (u,v,ddict[data]).
If True, return edge attribute dict in 3-tuple (u,v,ddict).
If False, return 2-tuple (u,v).</p>
</div></blockquote>
<p><strong>default</strong> : value, optional (default=None)</p>
<blockquote>
<div><p>Value used for edges that dont have the requested attribute.
Only relevant if data is not True or False.</p>
</div></blockquote>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">edge_list: list of edge tuples</p>
<blockquote class="last">
<div><p>Edges that are adjacent to any node in nbunch, or a list
of all edges if nbunch is not specified.</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<dl class="last docutils">
<dt><a class="reference internal" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.edges_iter" title="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.edges_iter"><code class="xref py py-obj docutils literal"><span class="pre">edges_iter</span></code></a></dt>
<dd>return an iterator over the edges</dd>
</dl>
</div>
<p class="rubric">Notes</p>
<p>Nodes in nbunch that are not in the graph will be (quietly) ignored.
For directed graphs this returns the out-edges.</p>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">G</span> <span class="o">=</span> <span class="n">nx</span><span class="o">.</span><span class="n">Graph</span><span class="p">()</span>   <span class="c1"># or DiGraph, MultiGraph, MultiDiGraph, etc</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_path</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_edge</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">,</span><span class="n">weight</span><span class="o">=</span><span class="mi">5</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">edges</span><span class="p">()</span>
<span class="go">[(0, 1), (1, 2), (2, 3)]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">edges</span><span class="p">(</span><span class="n">data</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span> <span class="c1"># default edge data is {} (empty dictionary)</span>
<span class="go">[(0, 1, {}), (1, 2, {}), (2, 3, {&#39;weight&#39;: 5})]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">list</span><span class="p">(</span><span class="n">G</span><span class="o">.</span><span class="n">edges_iter</span><span class="p">(</span><span class="n">data</span><span class="o">=</span><span class="s1">&#39;weight&#39;</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="mi">1</span><span class="p">))</span>
<span class="go">[(0, 1, 1), (1, 2, 1), (2, 3, 5)]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">edges</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span><span class="mi">3</span><span class="p">])</span>
<span class="go">[(0, 1), (3, 2)]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">edges</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
<span class="go">[(0, 1)]</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.out_edges_iter">
<code class="descname">out_edges_iter</code><span class="sig-paren">(</span><em>nbunch=None</em>, <em>data=False</em>, <em>default=None</em><span class="sig-paren">)</span><a class="headerlink" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.out_edges_iter" title="Permalink to this definition">¶</a></dt>
<dd><p>Return an iterator over the edges.</p>
<p>Edges are returned as tuples with optional data
in the order (node, neighbor, data).</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>nbunch</strong> : iterable container, optional (default= all nodes)</p>
<blockquote>
<div><p>A container of nodes.  The container will be iterated
through once.</p>
</div></blockquote>
<p><strong>data</strong> : string or bool, optional (default=False)</p>
<blockquote>
<div><p>The edge attribute returned in 3-tuple (u,v,ddict[data]).
If True, return edge attribute dict in 3-tuple (u,v,ddict).
If False, return 2-tuple (u,v).</p>
</div></blockquote>
<p><strong>default</strong> : value, optional (default=None)</p>
<blockquote>
<div><p>Value used for edges that dont have the requested attribute.
Only relevant if data is not True or False.</p>
</div></blockquote>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><strong>edge_iter</strong> : iterator</p>
<blockquote class="last">
<div><p>An iterator of (u,v) or (u,v,d) tuples of edges.</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<dl class="last docutils">
<dt><a class="reference internal" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.edges" title="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.edges"><code class="xref py py-obj docutils literal"><span class="pre">edges</span></code></a></dt>
<dd>return a list of edges</dd>
</dl>
</div>
<p class="rubric">Notes</p>
<p>Nodes in nbunch that are not in the graph will be (quietly) ignored.
For directed graphs this returns the out-edges.</p>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">G</span> <span class="o">=</span> <span class="n">nx</span><span class="o">.</span><span class="n">DiGraph</span><span class="p">()</span>   <span class="c1"># or MultiDiGraph, etc</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_path</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_edge</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">,</span><span class="n">weight</span><span class="o">=</span><span class="mi">5</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">[</span><span class="n">e</span> <span class="k">for</span> <span class="n">e</span> <span class="ow">in</span> <span class="n">G</span><span class="o">.</span><span class="n">edges_iter</span><span class="p">()]</span>
<span class="go">[(0, 1), (1, 2), (2, 3)]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">list</span><span class="p">(</span><span class="n">G</span><span class="o">.</span><span class="n">edges_iter</span><span class="p">(</span><span class="n">data</span><span class="o">=</span><span class="kc">True</span><span class="p">))</span> <span class="c1"># default data is {} (empty dict)</span>
<span class="go">[(0, 1, {}), (1, 2, {}), (2, 3, {&#39;weight&#39;: 5})]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">list</span><span class="p">(</span><span class="n">G</span><span class="o">.</span><span class="n">edges_iter</span><span class="p">(</span><span class="n">data</span><span class="o">=</span><span class="s1">&#39;weight&#39;</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="mi">1</span><span class="p">))</span> 
<span class="go">[(0, 1, 1), (1, 2, 1), (2, 3, 5)]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">list</span><span class="p">(</span><span class="n">G</span><span class="o">.</span><span class="n">edges_iter</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span><span class="mi">2</span><span class="p">]))</span>
<span class="go">[(0, 1), (2, 3)]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">list</span><span class="p">(</span><span class="n">G</span><span class="o">.</span><span class="n">edges_iter</span><span class="p">(</span><span class="mi">0</span><span class="p">))</span>
<span class="go">[(0, 1)]</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.predecessors">
<code class="descname">predecessors</code><span class="sig-paren">(</span><em>n</em><span class="sig-paren">)</span><a class="headerlink" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.predecessors" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a list of predecessor nodes of n.</p>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.predecessors_iter">
<code class="descname">predecessors_iter</code><span class="sig-paren">(</span><em>n</em><span class="sig-paren">)</span><a class="headerlink" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.predecessors_iter" title="Permalink to this definition">¶</a></dt>
<dd><p>Return an iterator over predecessor nodes of n.</p>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.remove_cpds">
<code class="descname">remove_cpds</code><span class="sig-paren">(</span><em>*cpds</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/models/DynamicBayesianNetwork.html#DynamicBayesianNetwork.remove_cpds"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.remove_cpds" title="Permalink to this definition">¶</a></dt>
<dd><p>Removes the cpds that are provided in the argument.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>*cpds</strong> : list, set, tuple (array-like)</p>
<blockquote class="last">
<div><p>List of CPDs which are to be associated with the model. Each CPD
should be an instance of <cite>TabularCPD</cite>.</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">DynamicBayesianNetwork</span> <span class="k">as</span> <span class="n">DBN</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.factors.discrete</span> <span class="k">import</span> <span class="n">TabularCPD</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dbn</span> <span class="o">=</span> <span class="n">DBN</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dbn</span><span class="o">.</span><span class="n">add_edges_from</span><span class="p">([((</span><span class="s1">&#39;D&#39;</span><span class="p">,</span><span class="mi">0</span><span class="p">),(</span><span class="s1">&#39;G&#39;</span><span class="p">,</span><span class="mi">0</span><span class="p">)),((</span><span class="s1">&#39;I&#39;</span><span class="p">,</span><span class="mi">0</span><span class="p">),(</span><span class="s1">&#39;G&#39;</span><span class="p">,</span><span class="mi">0</span><span class="p">)),((</span><span class="s1">&#39;D&#39;</span><span class="p">,</span><span class="mi">0</span><span class="p">),(</span><span class="s1">&#39;D&#39;</span><span class="p">,</span><span class="mi">1</span><span class="p">)),((</span><span class="s1">&#39;I&#39;</span><span class="p">,</span><span class="mi">0</span><span class="p">),(</span><span class="s1">&#39;I&#39;</span><span class="p">,</span><span class="mi">1</span><span class="p">))])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">grade_cpd</span> <span class="o">=</span>  <span class="n">TabularCPD</span><span class="p">((</span><span class="s1">&#39;G&#39;</span><span class="p">,</span><span class="mi">0</span><span class="p">),</span> <span class="mi">3</span><span class="p">,</span> <span class="p">[[</span><span class="mf">0.3</span><span class="p">,</span><span class="mf">0.05</span><span class="p">,</span><span class="mf">0.9</span><span class="p">,</span><span class="mf">0.5</span><span class="p">],</span>
<span class="gp">... </span>                                     <span class="p">[</span><span class="mf">0.4</span><span class="p">,</span><span class="mf">0.25</span><span class="p">,</span><span class="mf">0.8</span><span class="p">,</span><span class="mf">0.03</span><span class="p">],</span>
<span class="gp">... </span>                                     <span class="p">[</span><span class="mf">0.3</span><span class="p">,</span><span class="mf">0.7</span><span class="p">,</span><span class="mf">0.02</span><span class="p">,</span><span class="mf">0.2</span><span class="p">]],</span> <span class="p">[(</span><span class="s1">&#39;I&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">),(</span><span class="s1">&#39;D&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">)],[</span><span class="mi">2</span><span class="p">,</span><span class="mi">2</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dbn</span><span class="o">.</span><span class="n">add_cpds</span><span class="p">(</span><span class="n">grade_cpd</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dbn</span><span class="o">.</span><span class="n">get_cpds</span><span class="p">()</span>
<span class="go">[&lt;TabularCPD representing P((&#39;G&#39;, 0):3 | (&#39;I&#39;, 0):2, (&#39;D&#39;, 0):2) at 0x3348ab0&gt;]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dbn</span><span class="o">.</span><span class="n">remove_cpds</span><span class="p">(</span><span class="n">grade_cpd</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dbn</span><span class="o">.</span><span class="n">get_cpds</span><span class="p">()</span>
<span class="go">[]</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.remove_edge">
<code class="descname">remove_edge</code><span class="sig-paren">(</span><em>u</em>, <em>v</em><span class="sig-paren">)</span><a class="headerlink" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.remove_edge" title="Permalink to this definition">¶</a></dt>
<dd><p>Remove the edge between u and v.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>u, v</strong> : nodes</p>
<blockquote>
<div><p>Remove the edge between nodes u and v.</p>
</div></blockquote>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Raises:</th><td class="field-body"><p class="first"><strong>NetworkXError</strong></p>
<blockquote class="last">
<div><p>If there is not an edge between u and v.</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<dl class="last docutils">
<dt><a class="reference internal" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.remove_edges_from" title="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.remove_edges_from"><code class="xref py py-obj docutils literal"><span class="pre">remove_edges_from</span></code></a></dt>
<dd>remove a collection of edges</dd>
</dl>
</div>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">G</span> <span class="o">=</span> <span class="n">nx</span><span class="o">.</span><span class="n">Graph</span><span class="p">()</span>   <span class="c1"># or DiGraph, etc</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_path</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">remove_edge</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">e</span> <span class="o">=</span> <span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">remove_edge</span><span class="p">(</span><span class="o">*</span><span class="n">e</span><span class="p">)</span> <span class="c1"># unpacks e from an edge tuple</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">e</span> <span class="o">=</span> <span class="p">(</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">,{</span><span class="s1">&#39;weight&#39;</span><span class="p">:</span><span class="mi">7</span><span class="p">})</span> <span class="c1"># an edge with attribute data</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">remove_edge</span><span class="p">(</span><span class="o">*</span><span class="n">e</span><span class="p">[:</span><span class="mi">2</span><span class="p">])</span> <span class="c1"># select first part of edge tuple</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.remove_edges_from">
<code class="descname">remove_edges_from</code><span class="sig-paren">(</span><em>ebunch</em><span class="sig-paren">)</span><a class="headerlink" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.remove_edges_from" title="Permalink to this definition">¶</a></dt>
<dd><p>Remove all edges specified in ebunch.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>ebunch: list or container of edge tuples</strong></p>
<blockquote class="last">
<div><p>Each edge given in the list or container will be removed
from the graph. The edges can be:</p>
<blockquote>
<div><ul class="simple">
<li>2-tuples (u,v) edge between u and v.</li>
<li>3-tuples (u,v,k) where k is ignored.</li>
</ul>
</div></blockquote>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<dl class="last docutils">
<dt><a class="reference internal" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.remove_edge" title="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.remove_edge"><code class="xref py py-obj docutils literal"><span class="pre">remove_edge</span></code></a></dt>
<dd>remove a single edge</dd>
</dl>
</div>
<p class="rubric">Notes</p>
<p>Will fail silently if an edge in ebunch is not in the graph.</p>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">G</span> <span class="o">=</span> <span class="n">nx</span><span class="o">.</span><span class="n">Graph</span><span class="p">()</span>   <span class="c1"># or DiGraph, MultiGraph, MultiDiGraph, etc</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_path</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ebunch</span><span class="o">=</span><span class="p">[(</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">),(</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">)]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">remove_edges_from</span><span class="p">(</span><span class="n">ebunch</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.remove_node">
<code class="descname">remove_node</code><span class="sig-paren">(</span><em>n</em><span class="sig-paren">)</span><a class="headerlink" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.remove_node" title="Permalink to this definition">¶</a></dt>
<dd><p>Remove node n.</p>
<p>Removes the node n and all adjacent edges.
Attempting to remove a non-existent node will raise an exception.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>n</strong> : node</p>
<blockquote>
<div><p>A node in the graph</p>
</div></blockquote>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Raises:</th><td class="field-body"><p class="first"><strong>NetworkXError</strong></p>
<blockquote class="last">
<div><p>If n is not in the graph.</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.remove_nodes_from" title="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.remove_nodes_from"><code class="xref py py-obj docutils literal"><span class="pre">remove_nodes_from</span></code></a></p>
</div>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">G</span> <span class="o">=</span> <span class="n">nx</span><span class="o">.</span><span class="n">Graph</span><span class="p">()</span>   <span class="c1"># or DiGraph, MultiGraph, MultiDiGraph, etc</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_path</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">edges</span><span class="p">()</span>
<span class="go">[(0, 1), (1, 2)]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">remove_node</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">edges</span><span class="p">()</span>
<span class="go">[]</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.remove_nodes_from">
<code class="descname">remove_nodes_from</code><span class="sig-paren">(</span><em>nbunch</em><span class="sig-paren">)</span><a class="headerlink" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.remove_nodes_from" title="Permalink to this definition">¶</a></dt>
<dd><p>Remove multiple nodes.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>nodes</strong> : iterable container</p>
<blockquote class="last">
<div><p>A container of nodes (list, dict, set, etc.).  If a node
in the container is not in the graph it is silently
ignored.</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.remove_node" title="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.remove_node"><code class="xref py py-obj docutils literal"><span class="pre">remove_node</span></code></a></p>
</div>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">G</span> <span class="o">=</span> <span class="n">nx</span><span class="o">.</span><span class="n">Graph</span><span class="p">()</span>   <span class="c1"># or DiGraph, MultiGraph, MultiDiGraph, etc</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_path</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">e</span> <span class="o">=</span> <span class="n">G</span><span class="o">.</span><span class="n">nodes</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">e</span>
<span class="go">[0, 1, 2]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">remove_nodes_from</span><span class="p">(</span><span class="n">e</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">nodes</span><span class="p">()</span>
<span class="go">[]</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.reverse">
<code class="descname">reverse</code><span class="sig-paren">(</span><em>copy=True</em><span class="sig-paren">)</span><a class="headerlink" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.reverse" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the reverse of the graph.</p>
<p>The reverse is a graph with the same nodes and edges
but with the directions of the edges reversed.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>copy</strong> : bool optional (default=True)</p>
<blockquote class="last">
<div><p>If True, return a new DiGraph holding the reversed edges.
If False, reverse the reverse graph is created using
the original graph (this changes the original graph).</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.selfloop_edges">
<code class="descname">selfloop_edges</code><span class="sig-paren">(</span><em>data=False</em>, <em>default=None</em><span class="sig-paren">)</span><a class="headerlink" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.selfloop_edges" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a list of selfloop edges.</p>
<p>A selfloop edge has the same node at both ends.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>data</strong> : string or bool, optional (default=False)</p>
<blockquote>
<div><p>Return selfloop edges as two tuples (u,v) (data=False)
or three-tuples (u,v,datadict) (data=True)
or three-tuples (u,v,datavalue) (data=&#8217;attrname&#8217;)</p>
</div></blockquote>
<p><strong>default</strong> : value, optional (default=None)</p>
<blockquote>
<div><p>Value used for edges that dont have the requested attribute.
Only relevant if data is not True or False.</p>
</div></blockquote>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><strong>edgelist</strong> : list of edge tuples</p>
<blockquote class="last">
<div><p>A list of all selfloop edges.</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.nodes_with_selfloops" title="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.nodes_with_selfloops"><code class="xref py py-obj docutils literal"><span class="pre">nodes_with_selfloops</span></code></a>, <a class="reference internal" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.number_of_selfloops" title="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.number_of_selfloops"><code class="xref py py-obj docutils literal"><span class="pre">number_of_selfloops</span></code></a></p>
</div>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">G</span> <span class="o">=</span> <span class="n">nx</span><span class="o">.</span><span class="n">Graph</span><span class="p">()</span>   <span class="c1"># or DiGraph, MultiGraph, MultiDiGraph, etc</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_edge</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="mi">1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_edge</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">selfloop_edges</span><span class="p">()</span>
<span class="go">[(1, 1)]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">selfloop_edges</span><span class="p">(</span><span class="n">data</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="go">[(1, 1, {})]</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.size">
<code class="descname">size</code><span class="sig-paren">(</span><em>weight=None</em><span class="sig-paren">)</span><a class="headerlink" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.size" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the number of edges.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>weight</strong> : string or None, optional (default=None)</p>
<blockquote>
<div><p>The edge attribute that holds the numerical value used
as a weight.  If None, then each edge has weight 1.</p>
</div></blockquote>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><strong>nedges</strong> : int</p>
<blockquote class="last">
<div><p>The number of edges or sum of edge weights in the graph.</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.number_of_edges" title="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.number_of_edges"><code class="xref py py-obj docutils literal"><span class="pre">number_of_edges</span></code></a></p>
</div>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">G</span> <span class="o">=</span> <span class="n">nx</span><span class="o">.</span><span class="n">Graph</span><span class="p">()</span>   <span class="c1"># or DiGraph, MultiGraph, MultiDiGraph, etc</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_path</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">size</span><span class="p">()</span>
<span class="go">3</span>
</pre></div>
</div>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">G</span> <span class="o">=</span> <span class="n">nx</span><span class="o">.</span><span class="n">Graph</span><span class="p">()</span>   <span class="c1"># or DiGraph, MultiGraph, MultiDiGraph, etc</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_edge</span><span class="p">(</span><span class="s1">&#39;a&#39;</span><span class="p">,</span><span class="s1">&#39;b&#39;</span><span class="p">,</span><span class="n">weight</span><span class="o">=</span><span class="mi">2</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_edge</span><span class="p">(</span><span class="s1">&#39;b&#39;</span><span class="p">,</span><span class="s1">&#39;c&#39;</span><span class="p">,</span><span class="n">weight</span><span class="o">=</span><span class="mi">4</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">size</span><span class="p">()</span>
<span class="go">2</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">size</span><span class="p">(</span><span class="n">weight</span><span class="o">=</span><span class="s1">&#39;weight&#39;</span><span class="p">)</span>
<span class="go">6.0</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.subgraph">
<code class="descname">subgraph</code><span class="sig-paren">(</span><em>nbunch</em><span class="sig-paren">)</span><a class="headerlink" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.subgraph" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the subgraph induced on nodes in nbunch.</p>
<p>The induced subgraph of the graph contains the nodes in nbunch
and the edges between those nodes.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>nbunch</strong> : list, iterable</p>
<blockquote>
<div><p>A container of nodes which will be iterated through once.</p>
</div></blockquote>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><strong>G</strong> : Graph</p>
<blockquote class="last">
<div><p>A subgraph of the graph with the same edge attributes.</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Notes</p>
<p>The graph, edge or node attributes just point to the original graph.
So changes to the node or edge structure will not be reflected in
the original graph while changes to the attributes will.</p>
<p>To create a subgraph with its own copy of the edge/node attributes use:
nx.Graph(G.subgraph(nbunch))</p>
<p>If edge attributes are containers, a deep copy can be obtained using:
G.subgraph(nbunch).copy()</p>
<p>For an inplace reduction of a graph to a subgraph you can remove nodes:
G.remove_nodes_from([ n in G if n not in set(nbunch)])</p>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">G</span> <span class="o">=</span> <span class="n">nx</span><span class="o">.</span><span class="n">Graph</span><span class="p">()</span>   <span class="c1"># or DiGraph, MultiGraph, MultiDiGraph, etc</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_path</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">H</span> <span class="o">=</span> <span class="n">G</span><span class="o">.</span><span class="n">subgraph</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">H</span><span class="o">.</span><span class="n">edges</span><span class="p">()</span>
<span class="go">[(0, 1), (1, 2)]</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.successors">
<code class="descname">successors</code><span class="sig-paren">(</span><em>n</em><span class="sig-paren">)</span><a class="headerlink" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.successors" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a list of successor nodes of n.</p>
<p>neighbors() and successors() are the same function.</p>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.successors_iter">
<code class="descname">successors_iter</code><span class="sig-paren">(</span><em>n</em><span class="sig-paren">)</span><a class="headerlink" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.successors_iter" title="Permalink to this definition">¶</a></dt>
<dd><p>Return an iterator over successor nodes of n.</p>
<p>neighbors_iter() and successors_iter() are the same.</p>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.to_directed">
<code class="descname">to_directed</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.to_directed" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a directed copy of the graph.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><strong>G</strong> : DiGraph</p>
<blockquote class="last">
<div><p>A deepcopy of the graph.</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Notes</p>
<p>This returns a &#8220;deepcopy&#8221; of the edge, node, and
graph attributes which attempts to completely copy
all of the data and references.</p>
<p>This is in contrast to the similar D=DiGraph(G) which returns a
shallow copy of the data.</p>
<p>See the Python copy module for more information on shallow
and deep copies, <a class="reference external" href="http://docs.python.org/library/copy.html">http://docs.python.org/library/copy.html</a>.</p>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">G</span> <span class="o">=</span> <span class="n">nx</span><span class="o">.</span><span class="n">Graph</span><span class="p">()</span>   <span class="c1"># or MultiGraph, etc</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_path</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">H</span> <span class="o">=</span> <span class="n">G</span><span class="o">.</span><span class="n">to_directed</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">H</span><span class="o">.</span><span class="n">edges</span><span class="p">()</span>
<span class="go">[(0, 1), (1, 0)]</span>
</pre></div>
</div>
<p>If already directed, return a (deep) copy</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">G</span> <span class="o">=</span> <span class="n">nx</span><span class="o">.</span><span class="n">DiGraph</span><span class="p">()</span>   <span class="c1"># or MultiDiGraph, etc</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_path</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">H</span> <span class="o">=</span> <span class="n">G</span><span class="o">.</span><span class="n">to_directed</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">H</span><span class="o">.</span><span class="n">edges</span><span class="p">()</span>
<span class="go">[(0, 1)]</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.to_undirected">
<code class="descname">to_undirected</code><span class="sig-paren">(</span><em>reciprocal=False</em><span class="sig-paren">)</span><a class="headerlink" href="#pgmpy.models.DynamicBayesianNetwork.DynamicBayesianNetwork.to_undirected" title="Permalink to this definition">¶</a></dt>
<dd><p>Return an undirected representation of the digraph.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>reciprocal</strong> : bool (optional)</p>
<blockquote>
<div><p>If True only keep edges that appear in both directions
in the original digraph.</p>
</div></blockquote>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><strong>G</strong> : Graph</p>
<blockquote class="last">
<div><p>An undirected graph with the same name and nodes and
with edge (u,v,data) if either (u,v,data) or (v,u,data)
is in the digraph.  If both edges exist in digraph and
their edge data is different, only one edge is created
with an arbitrary choice of which edge data to use.
You must check and correct for this manually if desired.</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Notes</p>
<p>If edges in both directions (u,v) and (v,u) exist in the
graph, attributes for the new undirected edge will be a combination of
the attributes of the directed edges.  The edge data is updated
in the (arbitrary) order that the edges are encountered.  For
more customized control of the edge attributes use add_edge().</p>
<p>This returns a &#8220;deepcopy&#8221; of the edge, node, and
graph attributes which attempts to completely copy
all of the data and references.</p>
<p>This is in contrast to the similar G=DiGraph(D) which returns a
shallow copy of the data.</p>
<p>See the Python copy module for more information on shallow
and deep copies, <a class="reference external" href="http://docs.python.org/library/copy.html">http://docs.python.org/library/copy.html</a>.</p>
<p>Warning: If you have subclassed DiGraph to use dict-like objects 
in the data structure, those changes do not transfer to the Graph
created by this method.</p>
</dd></dl>

</dd></dl>

</div>
</div>


          </div>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="factors.html" title="Factor"
             >next</a> |</li>
        <li class="right" >
          <a href="index.html" title="Welcome to pgmpy’s documentation!"
             >previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="index.html">pgmpy 0.1.2 documentation</a> &#187;</li> 
      </ul>
    </div>
    <div class="footer" role="contentinfo">
        &#169; Copyright 2016, Ankur Ankan.
      Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.5.1.
    </div>
  </body>
</html>